mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-19 04:19:57 -04:00
Load shcore.dll once for the monitors' DPI instead of on every call.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -252,11 +252,17 @@ static void to_utf8(const wchar_t *w, char *out, size_t n) {
|
|||||||
if (!WideCharToMultiByte(CP_UTF8, 0, w, -1, out, (int)n, NULL, NULL)) out[0] = 0;
|
if (!WideCharToMultiByte(CP_UTF8, 0, w, -1, out, (int)n, NULL, NULL)) out[0] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDpiForMonitor lives in shcore.dll, which the build does not link; 0 when it is missing.
|
// GetDpiForMonitor lives in shcore.dll, which the build does not link; 0 when it is missing. The library is loaded once
|
||||||
|
// and kept: the monitor list asks for every monitor's DPI each time it is built.
|
||||||
static UINT monitor_dpi(HMONITOR mon) {
|
static UINT monitor_dpi(HMONITOR mon) {
|
||||||
typedef HRESULT(WINAPI * GetDpiForMonitorFn)(HMONITOR, int, UINT *, UINT *);
|
typedef HRESULT(WINAPI * GetDpiForMonitorFn)(HMONITOR, int, UINT *, UINT *);
|
||||||
HMODULE lib = LoadLibraryExW(L"shcore.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
|
static GetDpiForMonitorFn fn;
|
||||||
GetDpiForMonitorFn fn = lib ? (GetDpiForMonitorFn)(void *)GetProcAddress(lib, "GetDpiForMonitor") : NULL;
|
static int looked;
|
||||||
|
if (!looked) {
|
||||||
|
HMODULE lib = LoadLibraryExW(L"shcore.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
|
||||||
|
fn = lib ? (GetDpiForMonitorFn)(void *)GetProcAddress(lib, "GetDpiForMonitor") : NULL;
|
||||||
|
looked = 1;
|
||||||
|
}
|
||||||
UINT x = 0, y = 0;
|
UINT x = 0, y = 0;
|
||||||
if (!fn || fn(mon, 0 /* MDT_EFFECTIVE_DPI */, &x, &y) != S_OK) x = 0;
|
if (!fn || fn(mon, 0 /* MDT_EFFECTIVE_DPI */, &x, &y) != S_OK) x = 0;
|
||||||
return x;
|
return x;
|
||||||
|
|||||||
Reference in New Issue
Block a user