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 | 1be0995e0ee4ec69426ae908ae8d05603dfaa905 (patch) | |
tree | 870763354b9a329cef61b0423b6f709a53da2691 | |
parent | 68db18e2b8e0217b2651e5e6f75051c1aa1564f9 (diff) | |
download | scintilla-mirror-1be0995e0ee4ec69426ae908ae8d05603dfaa905.tar.gz |
Bug [#2063]. On Windows 8.1 where GetDpiForWindow is not available, use
GetDpiForMonitor to emulate it.
-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 99885e5e4..60bdbfee6 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -251,6 +251,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; @@ -272,6 +276,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 {}; @@ -448,6 +459,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; } @@ -3413,6 +3432,10 @@ void Platform_Finalise(bool fromDllMain) { } } #endif + if (!fromDllMain && hDLLShcore) { + FreeLibrary(hDLLShcore); + hDLLShcore = {}; + } ListBoxX_Unregister(); } |