I minimize the form in the system tray (display the tray icon), while maintaining its button on the taskbar when it is not minimized. This implies the removal of the taskbar button when the form is minimized and otherwise restored.
The easiest way to achieve this is to hide / show the form, the minimized window does not show.
type
TForm1 = class(TForm)
TrayIcon1: TTrayIcon;
procedure TrayIcon1DblClick(Sender: TObject);
protected
procedure WMSize(var Message: TWMSize); message WM_SIZE;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.WMSize(var Message: TWMSize);
begin
inherited;
case Message.SizeType of
SIZE_MINIMIZED:
if not TrayIcon1.Visible then begin
TrayIcon1.Visible := True;
Hide;
end;
SIZE_RESTORED, SIZE_MAXIMIZED:
if TrayIcon1.Visible then begin
Show;
Application.BringToFront;
TrayIcon1.Visible := False;
end;
end;
end;
procedure TForm1.TrayIcon1DblClick(Sender: TObject);
begin
Show;
WindowState := wsNormal;
end;
The above application introduces a visual crash if the option "Animate windows when minimizing and maximizing" the OS is enabled (available through "SystemPropertiesPerformance.exe"). Minimize window animations skipped. It seems that the animation actually runs after minimizing the window. The window is already hidden in the code.
, . . , , , , - WM_SYSCOMMAND, , ( , ShowWindow ).
, , . SystemParametersInfo . , , , , DWM / DWM. . , 250 . , . , , , ( , , ...).
. : .