procedure TfrmNotifyIcon.AddIcon;
begin
with FIconData do
begin
cbSize := SizeOf(FIconData);
Wnd := Self.Handle;
uID := $DEDB;
uFlags := NIF_MESSAGE or NIF_ICON or NIF_TIP;
hIcon := Application.Icon.Handle;
uCallbackMessage := WM_NotifyIcon;
StrCopy(szTip, '托盘示例');
end;
Shell_NotifyIcon(NIM_Add, @FIconData);
end;
procedure TfrmNotifyIcon.AppMin;
begin
Application.MainForm.Hide;
//ShowWindow(Application.handle,SW_Hide);
end;
procedure TfrmNotifyIcon.DelIcon;
begin
Shell_NotifyIcon(NIM_Delete, @FIconData);
end;
procedure TfrmNotifyIcon.WndProc(var msg: TMessage);
var
pt: TPoint;
begin
inherited WndProc(msg);
case msg.Msg of
WM_NotifyIcon:
case msg.LParam of
WM_RBUTTONUP:
begin
if IsWindowVisible(Handle) then
Application.BringToFront
else begin
//SetForegroundWindow(Application.Handle);
GetCursorPos(pt);
//PpMenu.Popup(pt.x, pt.y);
end;
end;
WM_LBUTTONDBLCLK:
begin
Application.NormalizeTopMosts;
Application.Restore;
Application.BringToFront;
//ShowWindow(Application.Handle, SW_RESTORE);
//SetForegroundWindow(Application.Handle);
end;
end;
WM_CREATE: AddIcon;
WM_DESTROY: DelIcon;
WM_SYSCOMMAND: if msg.WParam = SC_MINIMIZE then AppMin;
end;
end;