diff options
| -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();  } | 
