aboutsummaryrefslogtreecommitdiff
path: root/src/dutil/dpiutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/dutil/dpiutil.cpp')
-rw-r--r--src/dutil/dpiutil.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/dutil/dpiutil.cpp b/src/dutil/dpiutil.cpp
index a27ee8c5..02a9580c 100644
--- a/src/dutil/dpiutil.cpp
+++ b/src/dutil/dpiutil.cpp
@@ -15,6 +15,7 @@
15#define DpiuExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DPIUTIL, p, x, s, __VA_ARGS__) 15#define DpiuExitOnInvalidHandleWithLastError(p, x, s, ...) ExitOnInvalidHandleWithLastErrorSource(DUTIL_SOURCE_DPIUTIL, p, x, s, __VA_ARGS__)
16#define DpiuExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DPIUTIL, e, x, s, __VA_ARGS__) 16#define DpiuExitOnWin32Error(e, x, s, ...) ExitOnWin32ErrorSource(DUTIL_SOURCE_DPIUTIL, e, x, s, __VA_ARGS__)
17 17
18static PFN_ADJUSTWINDOWRECTEXFORDPI vpfnAdjustWindowRectExForDpi = NULL;
18static PFN_GETDPIFORMONITOR vpfnGetDpiForMonitor = NULL; 19static PFN_GETDPIFORMONITOR vpfnGetDpiForMonitor = NULL;
19static PFN_GETDPIFORWINDOW vpfnGetDpiForWindow = NULL; 20static PFN_GETDPIFORWINDOW vpfnGetDpiForWindow = NULL;
20 21
@@ -37,6 +38,7 @@ DAPI_(void) DpiuInitialize()
37 if (SUCCEEDED(hr)) 38 if (SUCCEEDED(hr))
38 { 39 {
39 // Ignore failures. 40 // Ignore failures.
41 vpfnAdjustWindowRectExForDpi = reinterpret_cast<PFN_ADJUSTWINDOWRECTEXFORDPI>(::GetProcAddress(vhUser32Dll, "AdjustWindowRectExForDpi"));
40 vpfnGetDpiForWindow = reinterpret_cast<PFN_GETDPIFORWINDOW>(::GetProcAddress(vhUser32Dll, "GetDpiForWindow")); 42 vpfnGetDpiForWindow = reinterpret_cast<PFN_GETDPIFORWINDOW>(::GetProcAddress(vhUser32Dll, "GetDpiForWindow"));
41 } 43 }
42 44
@@ -57,11 +59,35 @@ DAPI_(void) DpiuUninitialize()
57 59
58 vhShcoreDll = NULL; 60 vhShcoreDll = NULL;
59 vhUser32Dll = NULL; 61 vhUser32Dll = NULL;
62 vpfnAdjustWindowRectExForDpi = NULL;
60 vpfnGetDpiForMonitor = NULL; 63 vpfnGetDpiForMonitor = NULL;
61 vpfnGetDpiForWindow = NULL; 64 vpfnGetDpiForWindow = NULL;
62 vfDpiuInitialized = FALSE; 65 vfDpiuInitialized = FALSE;
63} 66}
64 67
68DAPI_(void) DpiuAdjustWindowRect(
69 __in RECT* pWindowRect,
70 __in DWORD dwStyle,
71 __in BOOL fMenu,
72 __in DWORD dwExStyle,
73 __in UINT nDpi
74 )
75{
76 if (WS_SYSMENU & dwStyle)
77 {
78 dwStyle |= WS_CAPTION; // WS_CAPTION is required with WS_SYSMENU, AdjustWindowRect* won't work properly when it's not specified.
79 }
80
81 if (vpfnAdjustWindowRectExForDpi)
82 {
83 vpfnAdjustWindowRectExForDpi(pWindowRect, dwStyle, fMenu, dwExStyle, nDpi);
84 }
85 else
86 {
87 ::AdjustWindowRectEx(pWindowRect, dwStyle, fMenu, dwExStyle);
88 }
89}
90
65DAPI_(HRESULT) DpiuGetMonitorContextFromPoint( 91DAPI_(HRESULT) DpiuGetMonitorContextFromPoint(
66 __in const POINT* pt, 92 __in const POINT* pt,
67 __out DPIU_MONITOR_CONTEXT** ppMonitorContext 93 __out DPIU_MONITOR_CONTEXT** ppMonitorContext