Applications declared DPI-aware in the Windows environment

Applications that run on a Windows computer with desktop scaling enabled
gets scaled incorrectly since windows assumes that applications are
DPI-unaware unless declared otherwise.

This change declares the application DPI-aware, thus not automatically
scaled by the operating system.

The corresponding library call requires Windows 8.1 or later.
This commit is contained in:
Björn Blissing
2017-11-30 13:00:54 +01:00
parent 09eefd7973
commit 9fac39c5e0

View File

@@ -144,6 +144,26 @@ static CloseTouchInputHandleFunc *closeTouchInputHandleFunc = NULL;
static GetTouchInputInfoFunc *getTouchInputInfoFunc = NULL;
static GetPointerTypeFunc *getPointerTypeFunc = NULL;
// DPI Awareness
#if(WINVER >= 0x0603)
#ifndef DPI_ENUMS_DECLARED
typedef enum PROCESS_DPI_AWARENESS {
PROCESS_DPI_UNAWARE = 0,
PROCESS_SYSTEM_DPI_AWARE = 1,
PROCESS_PER_MONITOR_DPI_AWARE = 2
} PROCESS_DPI_AWARENESS;
#endif // DPI_ENUMS_DECLARED
typedef
BOOL
(WINAPI SetProcessDpiAwarenessFunc(
PROCESS_DPI_AWARENESS dpi_awareness));
static SetProcessDpiAwarenessFunc *setProcessDpiAwareness = NULL;
#endif
@@ -765,6 +785,21 @@ Win32WindowingSystem::Win32WindowingSystem()
FreeLibrary( hModule);
}
}
#if(WINVER >= 0x0603)
// For Windows 8.1 and higher
//
// Per monitor DPI aware.This app checks for the DPI when it is created and adjusts the scale factor
// whenever the DPI changes.These applications are not automatically scaled by the system.
HMODULE hModuleShore = LoadLibrary("Shcore");
if (hModuleShore) {
setProcessDpiAwareness = (SetProcessDpiAwarenessFunc *) GetProcAddress(hModuleShore, "SetProcessDpiAwareness");
if (setProcessDpiAwareness) {
(*setProcessDpiAwareness)(PROCESS_DPI_AWARENESS::PROCESS_PER_MONITOR_DPI_AWARE);
}
}
#endif
}
Win32WindowingSystem::~Win32WindowingSystem()