1
0
mirror of https://github.com/narzoul/DDrawCompat synced 2024-12-30 08:55:36 +01:00

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).
This commit is contained in:
narzoul 2020-05-09 21:15:09 +02:00
parent c67437d5bf
commit 8f67fd158c

View File

@ -3,6 +3,7 @@
#include <Windows.h>
#include <Psapi.h>
#include <ShellScalingApi.h>
#include <timeapi.h>
#include <Uxtheme.h>
@ -177,6 +178,21 @@ namespace
Compat::Log() << "Environment variable " << var << " = \"" << value << '"';
}
void setDpiAwareness()
{
HMODULE shcore = LoadLibrary("shcore");
if (shcore)
{
auto setProcessDpiAwareness = reinterpret_cast<decltype(&SetProcessDpiAwareness)>(
Compat::getProcAddress(shcore, "SetProcessDpiAwareness"));
if (setProcessDpiAwareness && SUCCEEDED(setProcessDpiAwareness(PROCESS_PER_MONITOR_DPI_AWARE)))
{
return;
}
}
SetProcessDPIAware();
}
template <typename Param>
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();