Home » U++ Library support » U++ Core » Windows7 compatibility (Add workaround for 2 DPI functions not present in windows7)
| Windows7 compatibility [message #62042] |
Mon, 27 July 2026 11:10 |
mdelfede
Messages: 1313 Registered: September 2007
|
Ultimate Contributor |
|
|
Hi,
I recompiled my app for a customer and it complained about 2 missing functions: GetDpiForWindow and GetSystemMetricsForDpi.
I found that he's still using windows7 and that providing a workaround inside Win32Proc.cpp solves the issue.
I added this:
static UINT CompatGetDpiForWindow(HWND hwnd)
{
typedef UINT (WINAPI *GetDpiForWindowFn)(HWND);
static GetDpiForWindowFn fn =
(GetDpiForWindowFn)GetProcAddress(
GetModuleHandleA("user32.dll"),
"GetDpiForWindow"
);
if(fn)
return fn(hwnd);
// Windows 7: non esiste DPI per-monitor.
HDC dc = GetDC(hwnd);
UINT dpi = dc ? (UINT)GetDeviceCaps(dc, LOGPIXELSX) : 96;
if(dc)
ReleaseDC(hwnd, dc);
return dpi ? dpi : 96;
}
static int CompatGetSystemMetricsForDpi(int index, UINT dpi)
{
typedef int (WINAPI *GetSystemMetricsForDpiFn)(int, UINT);
static GetSystemMetricsForDpiFn fn =
(GetSystemMetricsForDpiFn)GetProcAddress(
GetModuleHandleA("user32.dll"),
"GetSystemMetricsForDpi"
);
if(fn)
return fn(index, dpi);
// Su Windows 7 il DPI è unico per tutto il desktop:
// GetSystemMetrics restituisce già le metriche appropriate.
return GetSystemMetrics(index);
}
and replaced the few calls to the compatibility functions
Ciao
Max
|
|
|
|
Goto Forum:
Current Time: Sat Aug 01 00:03:52 GMT+2 2026
Total time taken to generate the page: 0.00571 seconds
|