From b5d927baa542f2320b0d23b81708301159a21285 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Tue, 3 Oct 2023 16:22:43 -0500 Subject: [PATCH] Force windows window to be correct size when restoring window on maximize from minimize. --- .../Engine/Platform/Windows/WindowsWindow.cpp | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Platform/Windows/WindowsWindow.cpp b/Source/Engine/Platform/Windows/WindowsWindow.cpp index d712102fa..906816bf0 100644 --- a/Source/Engine/Platform/Windows/WindowsWindow.cpp +++ b/Source/Engine/Platform/Windows/WindowsWindow.cpp @@ -711,8 +711,27 @@ void WindowsWindow::CheckForWindowResize() // Cache client size RECT rect; GetClientRect(_handle, &rect); - const int32 width = Math::Max(rect.right - rect.left, 0L); - const int32 height = Math::Max(rect.bottom - rect.top, 0L); + int32 width = Math::Max(rect.right - rect.left, 0L); + int32 height = Math::Max(rect.bottom - rect.top, 0L); + + // Check for windows maximized size and see if it needs to adjust position if needed + if (_maximized) + { + // Pick the current monitor data for sizing + const HMONITOR monitor = MonitorFromWindow(_handle, MONITOR_DEFAULTTONEAREST); + MONITORINFO monitorInfo; + monitorInfo.cbSize = sizeof(MONITORINFO); + GetMonitorInfoW(monitor, &monitorInfo); + + auto cwidth = monitorInfo.rcWork.right - monitorInfo.rcWork.left; + auto cheight = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top; + if (width > cwidth && height > cheight) + { + width = cwidth; + height = cheight; + SetWindowPos(_handle, HWND_TOP, monitorInfo.rcWork.left, monitorInfo.rcWork.top, width, height, SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER); + } + } _clientSize = Float2(static_cast(width), static_cast(height)); // Check if window size has been changed