ModifyTrayIcon(NIM_DELETE,Application.Icon.Handle );//删除
ModifyTrayIcon(NIM_ADD,Application.Icon.Handle );//添加
ModifyTrayIcon(NIM_MODIFY,Application.Icon.Handle );//修改
procedure TForm1.ModifyTrayIcon(Action: DWORD;ico:THandle);
var
NIData: TNotifyIconData;
begin
with NIData do
begin
cbSize := sizeof(TNotifyIconData);
UID := 0;
uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
uCallBackMessage := WM_TRAYICON;
Wnd := Handle;
HICON := ico;
StrPCopy(szTip, Application.Title);
end;
Shell_NotifyIcon(Action, @NIData);
end;
//响应鼠标事件。
procedure WMTrayIcon(var message: TMessage); message WM_TRAYICON;
procedure TForm1.WMTrayIcon(var message: TMessage);
var
MousePos: TPoint;
begin
if message.LPARAM = WM_RBUTTONDOWN then //鼠标右键单击图标
begin
SetActiveWindow(Handle);
GetCursorPos(MousePos);
PopupMenu1.Popup(MousePos.X, MousePos.Y);
end;
if message.LPARAM = WM_LBUTTONDBLCLK then //鼠标左键双击图标
begin
Form1.Show;
Form1.BringToFront ;
end;
end;