Fix contentSizeToWindowSize for windows with a menu or an extended style

This commit is contained in:
Mark Jansen 2025-02-26 22:58:06 +01:00 committed by Chris Thrasher
parent 3528fcb293
commit 3cf85e6b19

View File

@ -579,9 +579,13 @@ void WindowImplWin32::grabCursor(bool grabbed)
////////////////////////////////////////////////////////////
Vector2i WindowImplWin32::contentSizeToWindowSize(Vector2u size)
{
// SetWindowPos wants the total size of the window (including title bar and borders) so we have to compute it
// SetWindowPos wants the total size of the window (including title bar, borders, and menu) so we have to compute it
const auto style = static_cast<DWORD>(GetWindowLongPtr(m_handle, GWL_STYLE));
const BOOL hasMenu = ((style & WS_CHILD) == 0) && GetMenu(m_handle) != nullptr;
const auto exStyle = static_cast<DWORD>(GetWindowLongPtr(m_handle, GWL_EXSTYLE));
RECT rectangle = {0, 0, static_cast<long>(size.x), static_cast<long>(size.y)};
AdjustWindowRect(&rectangle, static_cast<DWORD>(GetWindowLongPtr(m_handle, GWL_STYLE)), false);
AdjustWindowRectEx(&rectangle, style, hasMenu, exStyle);
const auto width = rectangle.right - rectangle.left;
const auto height = rectangle.bottom - rectangle.top;