diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c index e1044e9478f..c92d9af2aa9 100644 --- a/dlls/user32/sysparams.c +++ b/dlls/user32/sysparams.c @@ -39,6 +39,7 @@ #include "winerror.h" #include "controls.h" +#include "win.h" #include "user_private.h" #include "wine/gdi_driver.h" #include "wine/unicode.h" @@ -3192,7 +3193,16 @@ BOOL WINAPI EnumDisplaySettingsExW(LPCWSTR lpszDeviceName, DWORD iModeNum, /********************************************************************** * get_monitor_dpi */ -UINT get_monitor_dpi( HWND hwnd ) +UINT get_monitor_dpi( HMONITOR monitor ) +{ + /* FIXME: use the monitor DPI instead */ + return system_dpi; +} + +/********************************************************************** + * get_win_monitor_dpi + */ +UINT get_win_monitor_dpi( HWND hwnd ) { /* FIXME: use the monitor DPI instead */ return system_dpi; @@ -3324,12 +3334,22 @@ UINT WINAPI GetDpiForSystem(void) */ BOOL WINAPI GetDpiForMonitorInternal( HMONITOR monitor, UINT type, UINT *x, UINT *y ) { - UINT dpi = system_dpi; - - WARN( "(%p, %u, %p, %p): semi-stub\n", monitor, type, x, y ); - - if (x) *x = dpi; - if (y) *y = dpi; + if (type > 2) + { + SetLastError( ERROR_BAD_ARGUMENTS ); + return FALSE; + } + if (!x || !y) + { + SetLastError( ERROR_INVALID_ADDRESS ); + return FALSE; + } + switch (GetAwarenessFromDpiAwarenessContext( GetThreadDpiAwarenessContext() )) + { + case DPI_AWARENESS_UNAWARE: *x = *y = USER_DEFAULT_SCREEN_DPI; break; + case DPI_AWARENESS_SYSTEM_AWARE: *x = *y = system_dpi; break; + default: *x = *y = get_monitor_dpi( monitor ); break; + } return TRUE; } diff --git a/dlls/user32/tests/sysparams.c b/dlls/user32/tests/sysparams.c index fec37b65e95..7903c9ada6f 100644 --- a/dlls/user32/tests/sysparams.c +++ b/dlls/user32/tests/sysparams.c @@ -46,6 +46,7 @@ static BOOL (WINAPI *pGetProcessDpiAwarenessInternal)(HANDLE,DPI_AWARENESS*); static BOOL (WINAPI *pSetProcessDpiAwarenessInternal)(DPI_AWARENESS); static UINT (WINAPI *pGetDpiForSystem)(void); static UINT (WINAPI *pGetDpiForWindow)(HWND); +static BOOL (WINAPI *pGetDpiForMonitorInternal)(HMONITOR,UINT,UINT*,UINT*); static DPI_AWARENESS_CONTEXT (WINAPI *pGetThreadDpiAwarenessContext)(void); static DPI_AWARENESS_CONTEXT (WINAPI *pSetThreadDpiAwarenessContext)(DPI_AWARENESS_CONTEXT); static DPI_AWARENESS_CONTEXT (WINAPI *pGetWindowDpiAwarenessContext)(HWND); @@ -3549,6 +3550,26 @@ static void test_dpi_window(void) dpi = pGetDpiForWindow( hwnd ); ok( dpi == (i == DPI_AWARENESS_UNAWARE ? USER_DEFAULT_SCREEN_DPI : real_dpi), "%lu: got %u / %u\n", i, dpi, real_dpi ); + if (pGetDpiForMonitorInternal) + { + BOOL res; + SetLastError( 0xdeadbeef ); + res = pGetDpiForMonitorInternal( MonitorFromWindow( hwnd, 0 ), 0, &dpi, NULL ); + ok( !res, "succeeded\n" ); + ok( GetLastError() == ERROR_INVALID_ADDRESS, "wrong error %u\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + res = pGetDpiForMonitorInternal( MonitorFromWindow( hwnd, 0 ), 3, &dpi, &dpi ); + ok( !res, "succeeded\n" ); + ok( GetLastError() == ERROR_BAD_ARGUMENTS, "wrong error %u\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + res = pGetDpiForMonitorInternal( MonitorFromWindow( hwnd, 0 ), 3, &dpi, NULL ); + ok( !res, "succeeded\n" ); + ok( GetLastError() == ERROR_BAD_ARGUMENTS, "wrong error %u\n", GetLastError() ); + res = pGetDpiForMonitorInternal( MonitorFromWindow( hwnd, 0 ), 0, &dpi, &dpi ); + ok( res, "failed err %u\n", GetLastError() ); + ok( dpi == (i == DPI_AWARENESS_UNAWARE ? USER_DEFAULT_SCREEN_DPI : real_dpi), + "%lu: got %u / %u\n", i, dpi, real_dpi ); + } msg.hwnd = hwnd; for (j = DPI_AWARENESS_UNAWARE; j <= DPI_AWARENESS_PER_MONITOR_AWARE; j++) { @@ -3660,6 +3681,7 @@ START_TEST(sysparams) pSetProcessDPIAware = (void*)GetProcAddress(hdll, "SetProcessDPIAware"); pGetDpiForSystem = (void*)GetProcAddress(hdll, "GetDpiForSystem"); pGetDpiForWindow = (void*)GetProcAddress(hdll, "GetDpiForWindow"); + pGetDpiForMonitorInternal = (void*)GetProcAddress(hdll, "GetDpiForMonitorInternal"); pSetProcessDpiAwarenessContext = (void*)GetProcAddress(hdll, "SetProcessDpiAwarenessContext"); pGetProcessDpiAwarenessInternal = (void*)GetProcAddress(hdll, "GetProcessDpiAwarenessInternal"); pSetProcessDpiAwarenessInternal = (void*)GetProcAddress(hdll, "SetProcessDpiAwarenessInternal"); diff --git a/dlls/user32/win.c b/dlls/user32/win.c index 28bc1f604ba..5f2ac4e0d76 100644 --- a/dlls/user32/win.c +++ b/dlls/user32/win.c @@ -2240,11 +2240,15 @@ UINT WINAPI GetDpiForWindow( HWND hwnd ) SetLastError( ERROR_INVALID_WINDOW_HANDLE ); return 0; } - if (win == WND_DESKTOP) return get_monitor_dpi( GetDesktopWindow() ); + if (win == WND_DESKTOP) + { + POINT pt = { 0, 0 }; + return get_monitor_dpi( MonitorFromPoint( pt, MONITOR_DEFAULTTOPRIMARY )); + } if (win != WND_OTHER_PROCESS) { ret = win->dpi; - if (!ret) ret = get_monitor_dpi( hwnd ); + if (!ret) ret = get_win_monitor_dpi( hwnd ); WIN_ReleasePtr( win ); } else diff --git a/dlls/user32/win.h b/dlls/user32/win.h index 15331c39d48..b6c162a7143 100644 --- a/dlls/user32/win.h +++ b/dlls/user32/win.h @@ -128,7 +128,8 @@ extern void WINPOS_ActivateOtherWindow( HWND hwnd ) DECLSPEC_HIDDEN; extern UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect ) DECLSPEC_HIDDEN; extern void WINPOS_SysCommandSizeMove( HWND hwnd, WPARAM wParam ) DECLSPEC_HIDDEN; -extern UINT get_monitor_dpi( HWND hwnd ) DECLSPEC_HIDDEN; +extern UINT get_monitor_dpi( HMONITOR monitor ) DECLSPEC_HIDDEN; +extern UINT get_win_monitor_dpi( HWND hwnd ) DECLSPEC_HIDDEN; extern BOOL set_window_pos( HWND hwnd, HWND insert_after, UINT swp_flags, const RECT *window_rect, const RECT *client_rect, const RECT *valid_rects ) DECLSPEC_HIDDEN;