Skip to content

Commit

Permalink
fix: #4449 move saved maximized window before set window position
Browse files Browse the repository at this point in the history
Closes #4449
  • Loading branch information
punker76 committed Feb 20, 2024
1 parent cd234ae commit fb2cf67
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/MahApps.Metro/Native/WinApiHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,20 @@ public static unsafe void SetWindowPlacement(Window? window, WINDOWPLACEMENT? wp
}

var hWnd = new WindowInteropHelper(window).EnsureHandle();

var placementBefore = new WINDOWPLACEMENT { length = (uint)Marshal.SizeOf<WINDOWPLACEMENT>() };
PInvoke.GetWindowPlacement((HWND)hWnd, &placementBefore);
if (placementBefore.showCmd is SHOW_WINDOW_CMD.SW_NORMAL or SHOW_WINDOW_CMD.SW_SHOWMAXIMIZED && placement.showCmd is SHOW_WINDOW_CMD.SW_SHOWMAXIMIZED)
{
if (PInvoke.MoveWindow((HWND)hWnd, placement.rcNormalPosition.X, placement.rcNormalPosition.Y, placement.rcNormalPosition.Width, placement.rcNormalPosition.Height, false) == false)
{
Trace.TraceWarning($"{window}: The window can not moved! (MoveWindow) {placement}");
}
}

if (PInvoke.SetWindowPlacement(new HWND(hWnd), &placement) == false)
{
Trace.TraceWarning($"{window}: The window placement {wp} could not be (SetWindowPlacement)!");
Trace.TraceWarning($"{window}: The window placement {wp} could not be set (SetWindowPlacement) {placement}!");
}
}

Expand Down
1 change: 1 addition & 0 deletions src/MahApps.Metro/NativeMethods.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LoadLibrary
LoadString
MapVirtualKey
MonitorFromWindow
MoveWindow
ReleaseCapture
SendMessage
SetWindowPlacement
Expand Down

0 comments on commit fb2cf67

Please sign in to comment.