diff --git a/delphi-backend/Source/PM.Bridge.pas b/delphi-backend/Source/PM.Bridge.pas index 21b7cc7..8957cd4 100644 --- a/delphi-backend/Source/PM.Bridge.pas +++ b/delphi-backend/Source/PM.Bridge.pas @@ -693,7 +693,8 @@ end; procedure TPMBridge.RestoreFromTray; var LFormHwnd, LAppHwnd: HWND; - LWasTrayHidden: Boolean; + LWasTrayHidden, LRestoreMax: Boolean; + LPlace: TWindowPlacement; begin // Tray icon stays in the tray — we only show the window again. LFormHwnd := MainFormHWND(FMainForm); @@ -713,6 +714,19 @@ begin // MinimizeToTray) vs merely taskbar-minimised (Visible but iconic). LWasTrayHidden := not FMainForm.Visible; + // Windows remembers "this minimised window was maximised" in the placement + // flags, but FMainForm.Show below re-applies FMX's own WindowState (normal) + // and loses it — hence a maximised window coming back normal after Win+D / + // Show desktop. Read the flag BEFORE showing so we can re-apply it. + LRestoreMax := False; + if not LWasTrayHidden then + begin + FillChar(LPlace, SizeOf(LPlace), 0); + LPlace.length := SizeOf(LPlace); + LRestoreMax := GetWindowPlacement(LFormHwnd, @LPlace) and + ((LPlace.flags and WPF_RESTORETOMAXIMIZED) <> 0); + end; + // Reverse order: show the app proxy first so the taskbar entry comes back, // then show and foreground the form. if LAppHwnd <> 0 then @@ -747,6 +761,11 @@ begin end; SetWindowPlacement(LFormHwnd, @FSavedPlacement); end + else if LRestoreMax then + // Was maximised before Windows minimised it (Win+D, taskbar, Show + // desktop): come back maximised. SW_RESTORE alone would land on the + // pre-maximise "normal" geometry. + ShowWindow(LFormHwnd, SW_SHOWMAXIMIZED) else begin ShowWindow(LFormHwnd, SW_SHOW);