From 4f04fb4fbd65e8d6ed79211fe1a09ccb61ed1127 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Wed, 11 Mar 2015 13:59:51 -0500 Subject: [PATCH] Don't use AdjustWindowRectEx to determine window sizes - GetSystemMetrics can lie about the window border sizes, so we can't trust it if the executable is flagged as Vista-targetting (default behavior for VS2012/2013). --- src/win32/fb_d3d9.cpp | 7 ++++--- src/win32/fb_ddraw.cpp | 7 ++++--- src/win32/i_input.cpp | 7 ++++--- src/win32/i_main.cpp | 6 +----- src/win32/i_movie.cpp | 7 ++++--- src/win32/st_start.cpp | 8 +++++--- 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/win32/fb_d3d9.cpp b/src/win32/fb_d3d9.cpp index ac8102cd2..e23275734 100644 --- a/src/win32/fb_d3d9.cpp +++ b/src/win32/fb_d3d9.cpp @@ -505,9 +505,10 @@ bool D3DFB::CreateResources() else { // Resize the window to match desired dimensions - int sizew = Width + GetSystemMetrics (SM_CXSIZEFRAME)*2; - int sizeh = Height + GetSystemMetrics (SM_CYSIZEFRAME) * 2 + - GetSystemMetrics (SM_CYCAPTION); + RECT rect = { 0, 0, Width, Height }; + AdjustWindowRectEx(&rect, WS_VISIBLE|WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW); + int sizew = rect.right - rect.left; + int sizeh = rect.bottom - rect.top; LOG2 ("Resize window to %dx%d\n", sizew, sizeh); VidResizing = true; // Make sure the window has a border in windowed mode diff --git a/src/win32/fb_ddraw.cpp b/src/win32/fb_ddraw.cpp index 71d37d564..2aa694f3b 100644 --- a/src/win32/fb_ddraw.cpp +++ b/src/win32/fb_ddraw.cpp @@ -308,9 +308,10 @@ bool DDrawFB::CreateResources () MaybeCreatePalette (); // Resize the window to match desired dimensions - int sizew = (Width << PixelDoubling) + GetSystemMetrics (SM_CXSIZEFRAME)*2; - int sizeh = (Height << PixelDoubling) + GetSystemMetrics (SM_CYSIZEFRAME) * 2 + - GetSystemMetrics (SM_CYCAPTION); + RECT rect = { 0, 0, Width << PixelDoubling, Height << PixelDoubling }; + AdjustWindowRectEx(&rect, WS_VISIBLE|WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW); + int sizew = rect.right - rect.left; + int sizeh = rect.bottom - rect.top; LOG2 ("Resize window to %dx%d\n", sizew, sizeh); VidResizing = true; // Make sure the window has a border in windowed mode diff --git a/src/win32/i_input.cpp b/src/win32/i_input.cpp index 37c91d908..ed7c81cf1 100644 --- a/src/win32/i_input.cpp +++ b/src/win32/i_input.cpp @@ -531,9 +531,10 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) if (screen && !VidResizing) { LPMINMAXINFO mmi = (LPMINMAXINFO)lParam; - mmi->ptMinTrackSize.x = SCREENWIDTH + GetSystemMetrics (SM_CXSIZEFRAME) * 2; - mmi->ptMinTrackSize.y = SCREENHEIGHT + GetSystemMetrics (SM_CYSIZEFRAME) * 2 + - GetSystemMetrics (SM_CYCAPTION); + RECT rect = { 0, 0, screen->GetWidth(), screen->GetHeight() }; + AdjustWindowRectEx(&rect, WS_VISIBLE|WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW); + mmi->ptMinTrackSize.x = rect.right - rect.left; + mmi->ptMinTrackSize.y = rect.bottom - rect.top; return 0; } break; diff --git a/src/win32/i_main.cpp b/src/win32/i_main.cpp index ca12b659f..f2a4fab4d 100644 --- a/src/win32/i_main.cpp +++ b/src/win32/i_main.cpp @@ -907,11 +907,7 @@ void DoMain (HINSTANCE hInstance) FixPathSeperator(program); progdir.Truncate((long)strlen(program)); progdir.UnlockBuffer(); -/* - height = GetSystemMetrics (SM_CYFIXEDFRAME) * 2 + - GetSystemMetrics (SM_CYCAPTION) + 12 * 32; - width = GetSystemMetrics (SM_CXFIXEDFRAME) * 2 + 8 * 78; -*/ + width = 512; height = 384; diff --git a/src/win32/i_movie.cpp b/src/win32/i_movie.cpp index a0598cbb6..81d16acb2 100644 --- a/src/win32/i_movie.cpp +++ b/src/win32/i_movie.cpp @@ -206,9 +206,10 @@ LRESULT CALLBACK MovieWndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lP if (screen && !FullVideo) { LPMINMAXINFO mmi = (LPMINMAXINFO)lParam; - mmi->ptMinTrackSize.x = SCREENWIDTH + GetSystemMetrics (SM_CXSIZEFRAME) * 2; - mmi->ptMinTrackSize.y = SCREENHEIGHT + GetSystemMetrics (SM_CYSIZEFRAME) * 2 + - GetSystemMetrics (SM_CYCAPTION); + RECT rect = { 0, 0, screen->GetWidth(), screen->GetHeight() }; + AdjustWindowRectEx(&rect, WS_VISIBLE|WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW); + mmi->ptMinTrackSize.x = rect.right - rect.left; + mmi->ptMinTrackSize.y = rect.bottom - rect.top; return 0; } break; diff --git a/src/win32/st_start.cpp b/src/win32/st_start.cpp index af7f7ad98..52c95d69b 100644 --- a/src/win32/st_start.cpp +++ b/src/win32/st_start.cpp @@ -1227,9 +1227,11 @@ void ST_Util_SizeWindowForBitmap (int scale) { rect.bottom = 0; } - w = StartupBitmap->bmiHeader.biWidth * scale + GetSystemMetrics (SM_CXSIZEFRAME)*2; - h = StartupBitmap->bmiHeader.biHeight * scale + rect.bottom - + GetSystemMetrics (SM_CYSIZEFRAME) * 2 + GetSystemMetrics (SM_CYCAPTION); + RECT sizerect = { 0, 0, StartupBitmap->bmiHeader.biWidth * scale, + StartupBitmap->bmiHeader.biHeight * scale + rect.bottom }; + AdjustWindowRectEx(&sizerect, WS_VISIBLE|WS_OVERLAPPEDWINDOW, FALSE, WS_EX_APPWINDOW); + w = sizerect.right - sizerect.left; + h = sizerect.bottom - sizerect.top; // Resize the window, but keep its center point the same, unless that // puts it partially offscreen.