procedure TForm1.WMICON(var msg: TMessage); var P: TPoint; begin case msg.LParam of WM_LBUTTONDOWN: begin GetCursorPos(p); SetForegroundWindow(Application.MainForm.Handle); PopupMenu1.Popup(P.X, P.Y); end; WM_LBUTTONDBLCLK: RestoreItemClick(Self); end; end;
procedure TForm1.WMSYSCOMMAND(var msg: TMessage); begin inherited; if (Msg.wParam = SC_MINIMIZE) then HideItemClick(Self); end;
procedure TForm1.RestoreMainForm; var i, j: Integer; begin Application.ShowMainForm := True; ShowWindow(Application.Handle, SW_RESTORE); ShowWindow(Application.MainForm.Handle, SW_RESTORE); if not ShownOnce then begin for I := 0 to Application.MainForm.ComponentCount - 1 do if Application.MainForm.Components[I] is TWinControl then with Application.MainForm.Components[I] as TWinControl do if Visible then begin ShowWindow(Handle, SW_SHOWDEFAULT); for J := 0 to ComponentCount - 1 do if Components[J] is TWinControl then ShowWindow((Components[J] as TWinControl).Handle, SW_SHOWDEFAULT); end; ShownOnce := True; end;
end;
procedure TForm1.CreateTrayIcon(n: Integer); var nidata: TNotifyIconData; begin with nidata do begin cbSize := SizeOf(TNotifyIconData); Wnd := Self.Handle; uID := 1; uFlags := NIF_ICON or NIF_MESSAGE or NIF_TIP; uCallBackMessage := WM_MYICONNOTIFY; hIcon := Application.Icon.Handle; StrPCopy(szTip, Application.Title); end; Shell_NotifyIcon(NIM_ADD, @nidata); end;
procedure TForm1.DeleteTrayIcon(n: Integer); var nidata: TNotifyIconData; begin with nidata do begin cbSize := SizeOf(TNotifyIconData); Wnd := Self.Handle; uID := 1; end; Shell_NotifyIcon(NIM_DELETE, @nidata); end;