const
ICON_ID = 1;
MI_ICONEVENT = WM_USER + 100;
在Private中声明事件:
procedure InstallIcon;
//装载托盘图标
procedure UnInstallIcon;
//卸载托盘图标
procedure IconOnClick(var message: TMessage);
//单击图标事件
message MI_ICONEVENT;
procedure TForm1.IconOnClick(var message: TMessage);
begin
if (message.LParam = WM_LBUTTONDOWN) then
begin
//鼠标右键
end;
if (message.LParam = WM_RBUTTONDOWN) then
begin
//鼠标左键事件
end;
end;
procedure TForm1.InstallIcon;
var
IconData: TNotifyIconData;
begin
sysTrayIcon := TIcon.Create;
sysTrayIcon := Application.Icon;
IconData.cbSize := sizeof(IconData);
IconData.Wnd := Handle;
IconData.uID := ICON_ID;
IconData.uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP;
IconData.uCallbackMessage := MI_ICONEVENT;
IconData.hIcon := sysTrayIcon.Handle;
IconData.szTip := 'Test';
Shell_NotifyIcon(NIM_ADD, @IconData);
end;
procedure TForm1.UnInstallIcon;
var
IconData: TNotifyIconData;
begin
IconData.cbSize := sizeof(IconData);
IconData.Wnd := Handle;
IconData.uID := ICON_ID;
Shell_NotifyIcon(NIM_DELETE, @IconData);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
InstallIcon;
ShowWindow(Form1.Handle, SW_HIDE);
ShowWindow(Application.Handle, SW_HIDE);
end;
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
UnInstallIcon;
sysTrayIcon.Free;
end;
procedure TForm1.FormActivate(Sender: TObject);
begin
ShowWindow(Form1.Handle, SW_HIDE);
ShowWindow(Application.Handle, SW_HIDE);
end;
你要的提示在相应的地方添加。