From 9f834614a94232fb3a6789dee19d702efec5a8ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Thu, 23 May 2024 10:52:45 +0200 Subject: [PATCH] user32: Test and implement GetDpiFromDpiAwarenessContext. --- dlls/user32/sysparams.c | 9 +++++++ dlls/user32/tests/sysparams.c | 47 +++++++++++++++++++++++++++++++++++ dlls/user32/user32.spec | 1 + include/winuser.h | 1 + 4 files changed, 58 insertions(+) diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c index 4bca30cce9a..ad117c12d03 100644 --- a/dlls/user32/sysparams.c +++ b/dlls/user32/sysparams.c @@ -700,6 +700,15 @@ DPI_AWARENESS WINAPI GetAwarenessFromDpiAwarenessContext( DPI_AWARENESS_CONTEXT } } +/*********************************************************************** + * GetDpiFromDpiAwarenessContext (USER32.@) + */ +UINT WINAPI GetDpiFromDpiAwarenessContext( DPI_AWARENESS_CONTEXT handle ) +{ + UINT context = get_ntuser_dpi_context( handle ); + return NTUSER_DPI_CONTEXT_GET_DPI( context ); +} + /*********************************************************************** * IsValidDpiAwarenessContext (USER32.@) */ diff --git a/dlls/user32/tests/sysparams.c b/dlls/user32/tests/sysparams.c index 27189474027..468ef3e6486 100644 --- a/dlls/user32/tests/sysparams.c +++ b/dlls/user32/tests/sysparams.c @@ -50,6 +50,7 @@ static BOOL (WINAPI *pLogicalToPhysicalPointForPerMonitorDPI)(HWND,POINT*); static BOOL (WINAPI *pPhysicalToLogicalPointForPerMonitorDPI)(HWND,POINT*); static LONG (WINAPI *pGetAutoRotationState)(PAR_STATE); static BOOL (WINAPI *pAreDpiAwarenessContextsEqual)(DPI_AWARENESS_CONTEXT,DPI_AWARENESS_CONTEXT); +static LONG (WINAPI *pGetDpiFromDpiAwarenessContext)(DPI_AWARENESS_CONTEXT); static BOOL strict; static int dpi, real_dpi; @@ -4156,6 +4157,50 @@ static void test_IsValidDpiAwarenessContext(void) } } +static void test_GetDpiFromDpiAwarenessContext(void) +{ + UINT ret; + + if (!pGetDpiFromDpiAwarenessContext) + { + win_skip( "GetDpiFromDpiAwarenessContext missing, skipping tests\n" ); + return; + } + + ret = pGetDpiFromDpiAwarenessContext( 0 ); + ok( !ret, "GetDpiFromDpiAwarenessContext returned %u\n", ret ); + + ret = pGetDpiFromDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x11 ); + ok( ret == 0, "GetDpiFromDpiAwarenessContext returned %u\n", ret ); + ret = pGetDpiFromDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x12 ); + ok( ret == 0, "GetDpiFromDpiAwarenessContext returned %u\n", ret ); + ret = pGetDpiFromDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x22 ); + ok( ret == 0, "GetDpiFromDpiAwarenessContext returned %u\n", ret ); + ret = pGetDpiFromDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x6010 ); + ok( ret == 96, "GetDpiFromDpiAwarenessContext returned %u\n", ret ); + ret = pGetDpiFromDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x6011 ); + ok( ret == 96, "GetDpiFromDpiAwarenessContext returned %u\n", ret ); + ret = pGetDpiFromDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x6111 ); + ok( ret == 97, "GetDpiFromDpiAwarenessContext returned %u\n", ret ); + ret = pGetDpiFromDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x7811 ); + ok( ret == 120, "GetDpiFromDpiAwarenessContext returned %u\n", ret ); + ret = pGetDpiFromDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x10011 ); + ok( ret == 256, "GetDpiFromDpiAwarenessContext returned %u\n", ret ); + ret = pGetDpiFromDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)0x40006010 ); + ok( ret == 96, "GetDpiFromDpiAwarenessContext returned %u\n", ret ); + + ret = pGetDpiFromDpiAwarenessContext( DPI_AWARENESS_CONTEXT_UNAWARE ); + ok( ret == 96, "GetDpiFromDpiAwarenessContext returned %u\n", ret ); + ret = pGetDpiFromDpiAwarenessContext( DPI_AWARENESS_CONTEXT_SYSTEM_AWARE ); + ok( ret == real_dpi, "GetDpiFromDpiAwarenessContext returned %u\n", ret ); + ret = pGetDpiFromDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE ); + ok( ret == 0, "GetDpiFromDpiAwarenessContext returned %u\n", ret ); + ret = pGetDpiFromDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 ); + ok( ret == 0, "GetDpiFromDpiAwarenessContext returned %u\n", ret ); + ret = pGetDpiFromDpiAwarenessContext( DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED ); + ok( ret == 96, "GetDpiFromDpiAwarenessContext returned %u\n", ret ); +} + static void test_dpi_context(void) { DPI_AWARENESS awareness; @@ -4591,6 +4636,7 @@ START_TEST(sysparams) pPhysicalToLogicalPointForPerMonitorDPI = (void*)GetProcAddress(hdll, "PhysicalToLogicalPointForPerMonitorDPI"); pGetAutoRotationState = (void*)GetProcAddress(hdll, "GetAutoRotationState"); pAreDpiAwarenessContextsEqual = (void*)GetProcAddress(hdll, "AreDpiAwarenessContextsEqual"); + pGetDpiFromDpiAwarenessContext = (void*)GetProcAddress(hdll, "GetDpiFromDpiAwarenessContext"); hInstance = GetModuleHandleA( NULL ); hdc = GetDC(0); @@ -4623,6 +4669,7 @@ START_TEST(sysparams) test_GetAutoRotationState( ); test_SetThreadDpiAwarenessContext(); test_IsValidDpiAwarenessContext(); + test_GetDpiFromDpiAwarenessContext(); change_counter = 0; change_last_param = 0; diff --git a/dlls/user32/user32.spec b/dlls/user32/user32.spec index 21fa904082c..20ca6219bcd 100644 --- a/dlls/user32/user32.spec +++ b/dlls/user32/user32.spec @@ -302,6 +302,7 @@ @ stdcall GetDpiForMonitorInternal(long long ptr ptr) NtUserGetDpiForMonitor @ stdcall GetDpiForSystem() @ stdcall GetDpiForWindow(long) +@ stdcall GetDpiFromDpiAwarenessContext(long) @ stdcall GetFocus() @ stdcall GetForegroundWindow() NtUserGetForegroundWindow @ stdcall GetGestureConfig(long long long ptr ptr long) diff --git a/include/winuser.h b/include/winuser.h index 7c387e69f54..7d7a2dc557d 100644 --- a/include/winuser.h +++ b/include/winuser.h @@ -4116,6 +4116,7 @@ WINUSERAPI DWORD WINAPI GetAppCompatFlags(HTASK); WINUSERAPI SHORT WINAPI GetAsyncKeyState(INT); WINUSERAPI BOOL WINAPI GetAutoRotationState(AR_STATE*); WINUSERAPI DPI_AWARENESS WINAPI GetAwarenessFromDpiAwarenessContext(DPI_AWARENESS_CONTEXT); +WINUSERAPI UINT WINAPI GetDpiFromDpiAwarenessContext(DPI_AWARENESS_CONTEXT); WINUSERAPI HWND WINAPI GetCapture(void); WINUSERAPI UINT WINAPI GetCaretBlinkTime(void); WINUSERAPI BOOL WINAPI GetCaretPos(LPPOINT);