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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Emmanuel PASQUIERFreelance Project ManagerCommented:
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
Emmanuel PASQUIERFreelance Project ManagerCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.