From 32e0a0afed9d549681d9613ee6200b6c8035026d Mon Sep 17 00:00:00 2001 From: Mario Romero Date: Fri, 17 Jun 2022 20:43:47 -0400 Subject: [PATCH] Get and set size does not longer consider titlebar and drag borders --- src/CrossWindow/Win32/Win32Window.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/CrossWindow/Win32/Win32Window.cpp b/src/CrossWindow/Win32/Win32Window.cpp index 9b21ce6..3c02e10 100644 --- a/src/CrossWindow/Win32/Win32Window.cpp +++ b/src/CrossWindow/Win32/Win32Window.cpp @@ -263,7 +263,19 @@ void Window::setPosition(unsigned x, unsigned y) void Window::setSize(unsigned width, unsigned height) { - SetWindowPos(hwnd, nullptr, -1, -1, width, height, + RECT rect, frame, border; + GetWindowRect(hwnd, &rect); + DwmGetWindowAttribute(hwnd, DWMWA_EXTENDED_FRAME_BOUNDS, &frame, sizeof(RECT)); + + border.left = frame.left - rect.left; + border.top = frame.top - rect.top; + border.right = rect.right - frame.right; + border.bottom = rect.bottom - frame.bottom; + + int titlebarHeight = (GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYCAPTION) + + GetSystemMetrics(SM_CXPADDEDBORDER)); + + SetWindowPos(hwnd, nullptr, -1, -1, width + border.right + border.left, height + border.top + border.bottom + titlebarHeight, SWP_NOMOVE | SWP_NOREDRAW); } @@ -290,8 +302,9 @@ UVec2 Window::getPosition() const UVec2 Window::getWindowSize() const { RECT lpRect; - GetWindowRect(hwnd, &lpRect); - return UVec2(lpRect.right - lpRect.left, lpRect.bottom - lpRect.top); + DwmGetWindowAttribute(hwnd, DWMWA_EXTENDED_FRAME_BOUNDS, &lpRect, sizeof(lpRect)); + int titlebarHeight = (GetSystemMetrics(SM_CYFRAME) + GetSystemMetrics(SM_CYCAPTION) + GetSystemMetrics(SM_CXPADDEDBORDER)); + return UVec2(lpRect.right - lpRect.left, lpRect.bottom - lpRect.top - titlebarHeight); } UVec2 Window::getCurrentDisplaySize() const