procedure TForm1.ApplicationEvents1Minimize(Sender: TObject); begin if Application.MainFormOnTaskBar then ShowWindow(Application.MainForm.Handle, SW_HIDE) else ShowWindow(Application.Handle, SW_HIDE);
TrayIcon1.Visible := True; end;
procedure TForm1.ApplicationEvents1Restore(Sender: TObject); begin if Application.MainFormOnTaskBar then SetForegroundWindow(Application.MainForm.Handle) else SetForegroundWindow(Application.Handle);
TrayIcon1.Visible := False; end;
procedure TForm1.TrayIcon1Click(Sender: TObject); begin if Self.WindowState = wsMinimized then Application.Restore else Application.Minimize; end;
procedure TForm1.N1Click(Sender: TObject); begin TrayIcon1Click(nil); end;
procedure TForm1.TrayIcon1Click(Sender: TObject); begin if not IsIconic(Self.Handle) then SendMessage(Self.Handle, WM_SYSCOMMAND, SC_MINIMIZE, 0) else SendMessage(Self.Handle, WM_SYSCOMMAND, SC_RESTORE, 0); end;
----------------------------------------------
--
至于为什么打开 MainFormOnTaskBar ,请看官方解释: MainFormOnTaskBar must be True to use Windows Vista or Windows 7 Aero effects, including live taskbar thumbnails, Dynamic Windows, Windows Flip, and Windows Flip 3D.
procedure TForm1.TrayIcon1Click(Sender: TObject); begin if Self.WindowState = wsMinimized then begin {这里加一句就可以了} SendMessage(Application.Handle, WM_SIZE, SIZE_MINIMIZED, 0); Application.Restore; end else Application.Minimize; end;
----------------------------------------------
http://www.cnblogs.com/lzl_17948876/