diff options
| author | Zufu Liu <unknown> | 2020-06-06 13:36:36 +1000 |
|---|---|---|
| committer | Zufu Liu <unknown> | 2020-06-06 13:36:36 +1000 |
| commit | f1f8eeddbe3437c3e3f4f4580435996ea3cd0904 (patch) | |
| tree | 2d1410eecc3441625454dc44f6a965c244a1b56e | |
| parent | 1cd0eb50e9e90f08764278b69d97c38f5cb3c204 (diff) | |
| download | scintilla-mirror-f1f8eeddbe3437c3e3f4f4580435996ea3cd0904.tar.gz | |
Backport: Bug [#2063]. On Windows 8.1 where GetDpiForWindow is not available, use
GetDpiForMonitor to emulate it.
Backport of changeset 8285:426f23226f0d.
| -rw-r--r-- | win32/PlatWin.cxx | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 9f43addca..75d420068 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -256,6 +256,10 @@ UINT uSystemDPI = USER_DEFAULT_SCREEN_DPI; using GetDpiForWindowSig = UINT(WINAPI *)(HWND hwnd); GetDpiForWindowSig fnGetDpiForWindow = nullptr; +HMODULE hDLLShcore {}; +using GetDpiForMonitorSig = HRESULT (WINAPI *)(HMONITOR hmonitor, /*MONITOR_DPI_TYPE*/int dpiType, UINT *dpiX, UINT *dpiY); +GetDpiForMonitorSig fnGetDpiForMonitor = nullptr; + using GetSystemMetricsForDpiSig = int(WINAPI *)(int nIndex, UINT dpi); GetSystemMetricsForDpiSig fnGetSystemMetricsForDpi = nullptr; @@ -277,6 +281,13 @@ void LoadDpiForWindow() noexcept { uSystemDPI = ::GetDeviceCaps(hdcMeasure, LOGPIXELSY); ::DeleteDC(hdcMeasure); } + + if (!fnGetDpiForWindow) { + hDLLShcore = ::LoadLibraryExW(L"shcore.dll", {}, LOAD_LIBRARY_SEARCH_SYSTEM32); + if (hDLLShcore) { + fnGetDpiForMonitor = DLLFunction<GetDpiForMonitorSig>(hDLLShcore, "GetDpiForMonitor"); + } + } } HINSTANCE hinstPlatformRes {}; @@ -452,6 +463,14 @@ UINT DpiForWindow(WindowID wid) noexcept { if (fnGetDpiForWindow) { return fnGetDpiForWindow(HwndFromWindowID(wid)); } + if (fnGetDpiForMonitor) { + HMONITOR hMonitor = ::MonitorFromWindow(HwndFromWindowID(wid), MONITOR_DEFAULTTONEAREST); + UINT dpiX = 0; + UINT dpiY = 0; + if (fnGetDpiForMonitor(hMonitor, 0 /*MDT_EFFECTIVE_DPI*/, &dpiX, &dpiY) == S_OK) { + return dpiY; + } + } return uSystemDPI; } @@ -3005,6 +3024,10 @@ void Platform_Finalise(bool fromDllMain) { } } #endif + if (!fromDllMain && hDLLShcore) { + FreeLibrary(hDLLShcore); + hDLLShcore = {}; + } ListBoxX_Unregister(); } |
