CoolTrayIcon menu popup problem

I'm using Cooltrayicon this way in OnClick to shows the menu (I cannot use Autopopup, as the user can configure to show the menu or do something else on Tray Icon click).

GetCursorPos(CursorPos);
TrayIcon.PopupMenu.Popup(CursorPos.x, CursorPos.y);

The problem: the menu does not go away until I select an menuitem. When you click outside of the menu, it stays on.
ThomasReimannAsked:
Who is Participating?
 
epasquierConnect With a Mentor Commented:
I tested the methods above, and while some others said it working, I couldn't make the timer close the popup while debuging. Maybe it can work for you.

BUT

I have found another simple trick that works when the cursor click somewhere else, exactly like it does when autopopup is set to enabled : call SetForeGroundWindow just when the menu is poped up, using the onPopup event. It Worked fine with me (and Delphi 7 + CoolTrayIcon)
procedure TMainForm.PopupMenu1Popup(Sender: TObject);
begin
 SetForeGroundWindow(Handle);
end;

Open in new window

0
 
epasquierCommented:
I confirm that when the menu is not on AutoPopup it has the same problem as you are experiencing.

I saw in other forums that it's a fairly common problem with TPopupMenu, as well as the fact that there is no method of this object to close it (reverse of Popup method)

The way to tell a popup to close is this (it sends the escape key to its windows handle) :

SendMessage(popupmenu1.WindowHandle, WM_IME_KEYDOWN, VK_ESCAPE, 0);

you can at least do that when a timer is out (you enable it when using Popup)
procedure TMainForm.CoolTrayIcon1Click(Sender: TObject);
begin
 PopupMenu1.Popup(Mouse.CursorPos.X,Mouse.CursorPos.Y);
 PopupTimer.Enabled:=True;
end;

procedure TMainForm.PopupTimerTimer(Sender: TObject);
begin
 PopupTimer.Enabled:=False;
 SendMessage(popupmenu1.WindowHandle, WM_IME_KEYDOWN, VK_ESCAPE, 0);
end;

Open in new window

0
 
ThomasReimannAuthor Commented:
Closing the menu after X seconds if not really a solution. Closing the menu bevore the user wants it would be really bad, especially since some users of my program are blind and use a screenreader software.
0
All Courses

From novice to tech pro — start learning today.