如何在Delphi中关闭自定义定位的PopupMenu? [英] How to close custom positioned PopupMenu in delphi?
问题描述
我有一个项目,其中CoolTrayIcon
和PopupMenu
具有禁用的AutoPopup
属性.
我想放置PopupMenu并将其显示给用户.
位置确定,但如果用户单击鼠标左键或按ESC键,菜单不会关闭.
我没有找到任何类似Active
的属性,无论是否使用菜单,该属性都可以提供帮助.
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.
在这里放置菜单:
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:
您需要按以下步骤包装对Popup()
的调用:
You need to wrap the call to Popup()
as follows:
SetForegroundWindow(Handle);
PopupMenu1.Popup(pnt.X, yy);
PostMessage(Handle, WM_NULL, 0, 0);
在此代码中,Handle
是与通知图标关联的表单的窗口句柄.
In this code, Handle
is the window handle of the form associated with the notification icon.
这篇关于如何在Delphi中关闭自定义定位的PopupMenu?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!