summaryrefslogtreecommitdiff
path: root/alf/alfdpiaware.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'alf/alfdpiaware.cpp')
-rw-r--r--alf/alfdpiaware.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/alf/alfdpiaware.cpp b/alf/alfdpiaware.cpp
new file mode 100644
index 0000000..8f998f7
--- /dev/null
+++ b/alf/alfdpiaware.cpp
@@ -0,0 +1,46 @@
+#include "alfpriv.h"
+
+typedef BOOL (WINAPI *PSetProcessDpiAwarenessContext)(HANDLE);
+typedef BOOL (WINAPI *PSetProcessDPIAware)(void);
+
+static void
+ALF_SetSystemDpiAwareness(void)
+{
+ HMODULE user32 = GetModuleHandleA("user32.dll");
+
+ PSetProcessDPIAware p = (PSetProcessDPIAware)
+ (void*)GetProcAddress(user32, "SetProcessDPIAware");
+ if (p) {
+ p();
+ }
+}
+
+static void
+ALF_SetPerMonitorAwareness(void)
+{
+ HMODULE user32 = GetModuleHandleA("user32.dll");
+
+ PSetProcessDpiAwarenessContext p = (PSetProcessDpiAwarenessContext)
+ (void*)GetProcAddress(user32, "SetProcessDpiAwarenessContext");
+
+ if (p && p((HANDLE)-4)) /* DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 */
+ return;
+
+ ALF_SetSystemDpiAwareness();
+}
+
+void
+ALF_SetDpiAwareness(ALFDpiAwareness awareness)
+{
+ switch (awareness) {
+ case ALF_DPI_AWARENESS_PER_MONITOR_AWARE_V2:
+ ALF_SetPerMonitorAwareness();
+ return;
+ case ALF_DPI_AWARENESS_SYSTEM_AWARE:
+ ALF_SetSystemDpiAwareness();
+ return;
+ default:
+ // unaware, or could not set awareness
+ return;
+ }
+}