diff options
Diffstat (limited to 'src/dutil/dpiutil.cpp')
-rw-r--r-- | src/dutil/dpiutil.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/dutil/dpiutil.cpp b/src/dutil/dpiutil.cpp index edab8f01..a27ee8c5 100644 --- a/src/dutil/dpiutil.cpp +++ b/src/dutil/dpiutil.cpp | |||
@@ -62,6 +62,59 @@ DAPI_(void) DpiuUninitialize() | |||
62 | vfDpiuInitialized = FALSE; | 62 | vfDpiuInitialized = FALSE; |
63 | } | 63 | } |
64 | 64 | ||
65 | DAPI_(HRESULT) DpiuGetMonitorContextFromPoint( | ||
66 | __in const POINT* pt, | ||
67 | __out DPIU_MONITOR_CONTEXT** ppMonitorContext | ||
68 | ) | ||
69 | { | ||
70 | HRESULT hr = S_OK; | ||
71 | DPIU_MONITOR_CONTEXT* pMonitorContext = NULL; | ||
72 | HMONITOR hMonitor = NULL; | ||
73 | UINT dpiX = 0; | ||
74 | UINT dpiY = 0; | ||
75 | HDC hdc = NULL; | ||
76 | |||
77 | pMonitorContext = reinterpret_cast<DPIU_MONITOR_CONTEXT*>(MemAlloc(sizeof(DPIU_MONITOR_CONTEXT), TRUE)); | ||
78 | DpiuExitOnNull(pMonitorContext, hr, E_OUTOFMEMORY, "Failed to allocate memory for DpiuMonitorContext."); | ||
79 | |||
80 | hMonitor = ::MonitorFromPoint(*pt, MONITOR_DEFAULTTONEAREST); | ||
81 | DpiuExitOnNull(hMonitor, hr, E_FAIL, "Failed to get monitor from point."); | ||
82 | |||
83 | pMonitorContext->mi.cbSize = sizeof(pMonitorContext->mi); | ||
84 | if (!::GetMonitorInfoW(hMonitor, &pMonitorContext->mi)) | ||
85 | { | ||
86 | DpiuExitOnFailure(hr = E_OUTOFMEMORY, "Failed to get monitor info for point."); | ||
87 | } | ||
88 | |||
89 | if (vpfnGetDpiForMonitor) | ||
90 | { | ||
91 | hr = vpfnGetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY); | ||
92 | DpiuExitOnFailure(hr, "Failed to get DPI for monitor."); | ||
93 | |||
94 | pMonitorContext->nDpi = dpiX; | ||
95 | } | ||
96 | else | ||
97 | { | ||
98 | hdc = ::CreateDCW(L"DISPLAY", pMonitorContext->mi.szDevice, NULL, NULL); | ||
99 | DpiuExitOnNull(hdc, hr, E_OUTOFMEMORY, "Failed to get device context for monitor."); | ||
100 | |||
101 | pMonitorContext->nDpi = ::GetDeviceCaps(hdc, LOGPIXELSX); | ||
102 | } | ||
103 | |||
104 | *ppMonitorContext = pMonitorContext; | ||
105 | pMonitorContext = NULL; | ||
106 | |||
107 | LExit: | ||
108 | if (hdc) | ||
109 | { | ||
110 | ::ReleaseDC(NULL, hdc); | ||
111 | } | ||
112 | |||
113 | MemFree(pMonitorContext); | ||
114 | |||
115 | return hr; | ||
116 | } | ||
117 | |||
65 | DAPI_(void) DpiuGetWindowContext( | 118 | DAPI_(void) DpiuGetWindowContext( |
66 | __in HWND hWnd, | 119 | __in HWND hWnd, |
67 | __in DPIU_WINDOW_CONTEXT* pWindowContext | 120 | __in DPIU_WINDOW_CONTEXT* pWindowContext |