با کمی تغییرات ...
function MinimizeToTray(Restore: Boolean = False): Boolean;
var
hwndMain,
hwndTray: HWND;
rcWindow,
rcTray: TRect;
begin
Result := False;
hwndMain := Application.MainForm.Handle;
if IsWindow(hwndMain) then
begin
hwndTray := FindWindow('Shell_TrayWnd', nil);
hwndTray := FindWindowEx(hwndTray, 0, 'TrayNotifyWnd', nil);
hwndTray := FindWindowEx(hwndTray, 0, 'SysPager', nil);
hwndTray := FindWindowEx(hwndTray, 0, 'ToolbarWindow32', nil);
if hwndTray = INVALID_HANDLE_VALUE then Exit;
GetWindowRect(hwndMain, rcWindow);
GetWindowRect(hwndTray, rcTray);
if not Restore then begin
Result := DrawAnimatedRects(hwndMain, IDANI_CAPTION, rcWindow, rcTray);
if Result then Application.MainForm.Hide;
end else begin
Result := DrawAnimatedRects(hwndMain, IDANI_CAPTION, rcTray, rcWindow);
if Result then Application.MainForm.Show;
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
MinimizeToTray;
Sleep(1500);
MinimizeToTray(True)
end;
یا حق !!!