The CoolTrayIcon is working without this 'bug'.

subsimple.com/delphi.asp













Robert Meek wrote:
> I've experienced the same problem with a variety of Tray Icon components.
> They evidently don't respond to clicks made on the desktop.  But I switched
> to the one that comes with Raize components and it does!  The solution I
> used to use for this problem was to add a "Cancel" menu item to the popup
> menu that would allow the user to get rid of it without having to run a
> function.
>
> from Robert Meek dba "Tangentals Design"
> e-mail: [EMAIL PROTECTED]
> Freelance Windows Programming for XP and Vista 
> Also proud to be a Moderator of the "Delphi-List" at elists.org
>
> "Reality cannot be explained...only enjoyed or endured as your current
> perspective allows!"
>
> Hello,
>
> I have a little application that display only a tray icon and a menu.
> While it all works well there is something strange. When you right click
> then the menu pops up, but you have to click on a menu item to let the
> menu dissapear.
>
> Normally if you press <escape> or click somewhere els on the taskbar the
> menu should dissapear also.
>
> Any idea wy this behaviour? I copy the wholl code as it is only little.
>
> program Traytest;
>
> uses
>    Windows, Messages, ShellAPI, Menus, Dialogs, Forms, Registry, SysUtils;
>
> {$R *.RES}
>
> const
>    ICON_HINT = 'Test tray application';
>    MyClass = ICON_HINT + '_Class';
>    WindowName = ICON_HINT + '_WindowName';
>    WM_CIA_ICONMSG = WM_USER + 1;
>
> type
>   TPopup = class
>   private
>     Menu: TPopupMenu;
>     QuitTray: TMenuItem;
>     procedure Popup;
>     procedure QuitTrayClick(Sender: TObject);
>     procedure CreateMenu;
>     procedure DestroyMenu;
>   public
>     destructor  Destroy; override;
>   end;
>
> var
>    WndClass: TWndClass;
>    HInst: integer;
>    Handle: integer;
>    Msg: TMsg;
>    IconData: TNotifyIconData;
>    Popup: TPopup;
>
> { TPopup }
>
> procedure TPopup.CreateMenu;
> begin
>    QuitTray := TMenuItem.Create(nil);
>    QuitTray.Caption := 'Exit';
>    QuitTray.OnClick := QuitTrayClick;
>
>    Menu := TPopupMenu.Create(nil);
>    Menu.Items.Add([QuitTray]);
> end;
>
> destructor TPopup.Destroy;
> begin
>    DestroyMenu;
>    inherited;
> end;
>
> procedure TPopup.DestroyMenu;
> begin
>    try
>       QuitTray.Free;
>       Menu.Free;
>    except
>    end;
> end;
>
> procedure TPopup.Popup;
> var
>    P: TPoint;
> begin
>    if not Assigned(Menu) then
>       CreateMenu;
>
>    GetCursorPos(P);
>    Menu.Popup(P.X, P.Y);
>    Menu.Tag := 0;
> end;
>
> procedure TPopup.QuitTrayClick(Sender: TObject);
> begin
>    PostMessage(Handle, WM_QUIT, 0, 0);
> end;
>
> function WndProc(HWND, Msg, wParam, lParam: integer): integer; stdcall;
> begin
>    case Msg of
>       WM_CIA_ICONMSG:
>          case lParam of
>             WM_RBUTTONUP:
>                Popup.Popup;
>          end;
>    end;
>    Result := DefWindowProc(HWND, Msg, wParam, lParam);
> end;
>
> begin
>    HInst := GetModuleHandle(nil);
>    WndClass.style :=  0;
>    WndClass.lpfnWndproc := @WndProc;
>    WndClass.hInstance := HInst;
>    WndClass.hbrBackground := 0;
>    WndClass.lpszClassName := MyClass;
>    WndClass.hCursor := 0;
>    WndClass.hIcon := LoadIcon(hInst, 'MAINICON');
>    WndClass.lpszMenuName := nil;
>    WndClass.cbWndExtra := SizeOf(Pointer);
>    RegisterClass(WndClass);
>    Handle := CreateWindowEx(WS_EX_TOOLWINDOW, WndClass.lpszClassName,
> WindowName, WS_POPUP, 0, 0, 0, 0, 0, 0, HInst, nil);
>
>    IconData.cbSize := SizeOf(IconData);
>    IconData.Wnd := Handle;
>    IconData.uID := $DEDB;
>    IconData.uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
>    IconData.hIcon := LoadIcon(HInst, 'MAINICON');
>    IconData.uCallbackMessage := WM_CIA_ICONMSG;
>    CopyMemory(@IconData.szTip, PChar(ICON_HINT), Length(ICON_HINT) + 1);
>    Shell_NotifyIcon(NIM_ADD, @IconData);
>
>    Popup := TPopup.Create;
>    try
>       while GetMessage(Msg, 0, 0, 0) do begin
>          TranslateMessage(Msg);
>          DispatchMessage(Msg);
>       end;
>    finally
>       Shell_NotifyIcon(NIM_DELETE, @IconData);
>       DestroyWindow(Handle);
>       Popup.Free;
>    end;
> end.
>
> ---
> Rgds, Wilfried
> http://www.mestdagh.biz
>
> __________________________________________________
> Delphi-Talk mailing list -> Delphi-Talk@elists.org
> http://lists.elists.org/cgi-bin/mailman/listinfo/delphi-talk
>
> __________________________________________________
> Delphi-Talk mailing list -> Delphi-Talk@elists.org
> http://lists.elists.org/cgi-bin/mailman/listinfo/delphi-talk
>
>   
__________________________________________________
Delphi-Talk mailing list -> Delphi-Talk@elists.org
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi-talk

Reply via email to