1、托盘实现
const
ICON_ID = 1;
MI_ICONEVENT = WM_USER + 1;
//过程定义
private
procedure InstallIcon;
//装图标
procedure UnInstallIcon;
//卸载图标
procedure IconOnClick(var message: TMessage);
//单击图标
message MI_ICONEVENT;
procedure TForm1.IconOnClick(var message: TMessage);
var
p: TPoint;
begin
if (message.LParam = WM_RBUTTONDOWN) then
begin
GetCursorPos(p);
PopupMenu1.Popup(p.X, p.Y);
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 := 'Example';
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;
2、任务兰里没有图标:
在FormCreate和FormActivate中写入
ShowWindow(Form1.Handle, SW_HIDE);
ShowWindow(Application.Handle, SW_HIDE);