const WM_TrayMessage=WM_User+100;procedure AppMinimized(Sender: TObject); procedure WMTrayMessage(var msg:TMessage);message WM_TrayMessage;var NID:TNotifyIconData; ... procedure TFrmMain.WMTrayMessage(var msg:TMessage); var p:TPoint; begin if msg.LParam=WM_LButtonDown then begin ShowWindow(Application.Handle,SW_Show); Application.Restore; end else if msg.LParam=WM_RButtonDown then begin GetCursorPos(p); //pmTray.Popup(p.x,p.y); end; end;procedure TFrmMain.AppMinimized(Sender:TObject); begin NID.cbSize:=SizeOf(TNotifyIconData); NID.hIcon:=Application.Icon.Handle; NID.szTip:= 'XXX系统2.0版'; NID.uCallbackMessage:=WM_TrayMessage; NID.uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP; NID.uID:=0; NID.Wnd:=Handle; if b_IsIco then Shell_NotifyIcon(NIM_MODIFY,@NID) else Shell_NotifyIcon(NIM_ADD,@NID); ShowWindow(Application.Handle,SW_Hide); b_IsIco:=true; end;procedure TFrmMain.FormDestroy(Sender: TObject); begin Shell_NotifyIcon(NIM_DELETE,@NID); end;
procedure WMTrayMessage(var msg:TMessage);message WM_TrayMessage;var NID:TNotifyIconData;
...
procedure TFrmMain.WMTrayMessage(var msg:TMessage);
var
p:TPoint;
begin
if msg.LParam=WM_LButtonDown then
begin
ShowWindow(Application.Handle,SW_Show);
Application.Restore;
end
else if msg.LParam=WM_RButtonDown then
begin
GetCursorPos(p);
//pmTray.Popup(p.x,p.y);
end;
end;procedure TFrmMain.AppMinimized(Sender:TObject);
begin
NID.cbSize:=SizeOf(TNotifyIconData);
NID.hIcon:=Application.Icon.Handle;
NID.szTip:= 'XXX系统2.0版';
NID.uCallbackMessage:=WM_TrayMessage;
NID.uFlags:=NIF_ICON or NIF_MESSAGE or NIF_TIP;
NID.uID:=0;
NID.Wnd:=Handle;
if b_IsIco then
Shell_NotifyIcon(NIM_MODIFY,@NID)
else
Shell_NotifyIcon(NIM_ADD,@NID);
ShowWindow(Application.Handle,SW_Hide);
b_IsIco:=true;
end;procedure TFrmMain.FormDestroy(Sender: TObject);
begin
Shell_NotifyIcon(NIM_DELETE,@NID);
end;