I have a project with CoolTrayIcon
and PopupMenu
with disabled AutoPopup
property.
I would like to position the PopupMenu and show it for the user.
The position is OK but menu doesn't close if the user clicks away or press ESC button.
I have not found any property like Active
which could help if the menu is used or not.
Here I position the menu:
procedure TForm1.CoolTrayIcon1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
pnt: TPoint; yy:integer;
begin
GetCursorPos(pnt);
yy:=pnt.y; yy:=yy-500;
if (Button=mbRight) then begin
PopupMenu1.Popup(pnt.X, yy);
end;
end;
How could I manage to close menu if it is needed?
This is a known issue that is discussed here:
PRB: Menus for Notification Icons Do Not Work Correctly
You need to wrap the call to Popup()
as follows:
SetForegroundWindow(Handle);
PopupMenu1.Popup(pnt.X, yy);
PostMessage(Handle, WM_NULL, 0, 0);
In this code, Handle
is the window handle of the form associated with the notification icon.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With