From 8f67fd158c3ef995c04f85808e23323eb92ae0cf Mon Sep 17 00:00:00 2001 From: narzoul Date: Sat, 9 May 2020 21:15:09 +0200 Subject: [PATCH] Set per-monitor DPI awareness on Windows 8.1/10 Fixes an issue with the mouse being locked in top-left corner in Project Visitor, if DPI scaling is higher than 100% and the in-game resolution is much lower than the desktop resolution, e.g. 640x480 vs 1920x1080 (issue #41). --- DDrawCompat/Dll/DllMain.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/DDrawCompat/Dll/DllMain.cpp b/DDrawCompat/Dll/DllMain.cpp index ebddade..e41add3 100644 --- a/DDrawCompat/Dll/DllMain.cpp +++ b/DDrawCompat/Dll/DllMain.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -177,6 +178,21 @@ namespace Compat::Log() << "Environment variable " << var << " = \"" << value << '"'; } + void setDpiAwareness() + { + HMODULE shcore = LoadLibrary("shcore"); + if (shcore) + { + auto setProcessDpiAwareness = reinterpret_cast( + Compat::getProcAddress(shcore, "SetProcessDpiAwareness")); + if (setProcessDpiAwareness && SUCCEEDED(setProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE))) + { + return; + } + } + SetProcessDPIAware(); + } + template void suppressEmulatedDirectDraw(Param) { @@ -256,7 +272,7 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) SetProcessPriorityBoost(GetCurrentProcess(), disablePriorityBoost); SetProcessAffinityMask(GetCurrentProcess(), 1); timeBeginPeriod(1); - SetProcessDPIAware(); + setDpiAwareness(); SetThemeAppProperties(0); Win32::MsgHooks::installHooks();