我正在为我的程序创建一个 notifyIcon,将来它将独立于操作系统,但现在我正在编写 win-32 部分。
当我收到 WM_RBUTTONDOWN 消息后显示弹出菜单时,我显示一个菜单,但此菜单位于任务栏后面。如何创建一个位于任务栏前面的常规菜单?
问题在于 fmx.popupmenu,假设它与 VCL.popupmenu 具有相同的行为是错误的吗?
编辑代码:
{$IFDEF MSWINDOWS}
Tray:=TPWTrayIcon.Create((handle));
{$ENDIF MSWINDOWS}
Tray.popupmenu:=pmTray;
constructor TPWTrayIcon.Create(pHANDLE:TFMXHandle);
Var
HIco: HICON;
p:tMenuitem;
begin
{$IFDEF MSWINDOWS}
FHandle := AllocateHWnd(HandleIconMessage);
AHandle := FmxHandleToHWND(pHandle);
try
Hico:= LoadIcon(MainInstance,'MAINICON');
tIcon.cbSize := sizeof(tIcon);//TNotifyIconData);
with tIcon do begin
Wnd := FHandle;
uID := 123;
//guidItem:=123;
uFlags := NIF_ICON or NIF_MESSAGE or NIF_GUID or NIF_TIP;
uCallbackMessage := WM_NOTIFYICON;
hIcon := HIco;
uVersion:=NOTIFYICON_VERSION_4;
end;
Shell_NotifyIcon(NIM_ADD, @tIcon);
Shell_NotifyIcon(NIM_SETVERSION, @tIcon);
except
end;
{$ENDIF MSWINDOWS}
end;
procedure TPWTrayIcon.HandleIconMessage(var Msg: TMessage);
var
tmpPoint:TPoint;
begin
if Msg.Msg = WM_NOTIFYICON then begin
case LOWORD(Msg.LParam )of
WM_RBUTTONDOWN:
if Assigned(PopUp) then begin
Cardinal(tmpPoint):=(GetMessagePos);
{EDIT: the following doesnt work in Firemonkey}
//SetForegroundWindow(Application.Handle);
//Application.ProcessMessages;
if SetForegroundWindow(AHANDLE) then
Popup.Popup(tmpPoint.X,tmpPoint.Y);
end;
end;
end;
编辑:解决方法:
使用 VCL.菜单。而不是 Firemonkey.menus