From eeb0682ced3ab366a87f5c6775e7239573907299 Mon Sep 17 00:00:00 2001 From: narzoul Date: Fri, 28 Jun 2024 00:11:49 +0200 Subject: [PATCH] Prevent initial DPI scaling of dialog windows Fixes oversized dialogs (except non-client area) in some fullscreen games, e.g. Close Combat 4. Fixes mispositioned trackbar sliders in Red Alert 2. --- DDrawCompat/Gdi/WinProc.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/DDrawCompat/Gdi/WinProc.cpp b/DDrawCompat/Gdi/WinProc.cpp index 9a01aed..6ea0f63 100644 --- a/DDrawCompat/Gdi/WinProc.cpp +++ b/DDrawCompat/Gdi/WinProc.cpp @@ -53,6 +53,7 @@ namespace }; decltype(&DwmSetIconicThumbnail) g_dwmSetIconicThumbnail = nullptr; + decltype(&GetDpiForSystem) g_getDpiForSystem = nullptr; std::map g_menuMaxHeight; @@ -391,6 +392,16 @@ namespace return result; } + UINT WINAPI getDpiForSystem() + { + LOG_FUNC("GetDpiForSystem"); + if (0 != g_inCreateDialog || 0 != g_inMessageBox) + { + return LOG_RESULT(96); + } + return LOG_RESULT(g_getDpiForSystem()); + } + BOOL WINAPI getMessage(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, decltype(&GetMessageA) origGetMessage) { @@ -954,6 +965,13 @@ namespace Gdi g_dwmSetIconicThumbnail = reinterpret_cast( GetProcAddress(GetModuleHandle("dwmapi"), "DwmSetIconicThumbnail")); + g_getDpiForSystem = reinterpret_cast( + GetProcAddress(GetModuleHandle("user32"), "GetDpiForSystem")); + if (g_getDpiForSystem) + { + Compat::hookFunction(reinterpret_cast(g_getDpiForSystem), getDpiForSystem, "GetDpiForSystem"); + } + Compat::hookIatFunction(Dll::g_origDDrawModule, "SetWindowLongA", ddrawSetWindowLongA); SetWinEventHook(EVENT_OBJECT_CREATE, EVENT_OBJECT_CREATE,