From bd0cd09e69ef5feed483fb11401667544c68ee21 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Fri, 30 Mar 2018 12:37:55 +0200 Subject: [PATCH] user32: Implement SetProcessDpiAwarenessContext(). Signed-off-by: Alexandre Julliard --- dlls/user32/sysparams.c | 27 +++++++++++++++++++++++++-- dlls/user32/tests/sysparams.c | 26 ++++++++++++++++++++++++++ dlls/user32/user32.spec | 3 ++- include/winuser.h | 1 + 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c index 42e6a444a2c..2c4ff5ec8de 100644 --- a/dlls/user32/sysparams.c +++ b/dlls/user32/sysparams.c @@ -2942,6 +2942,28 @@ BOOL WINAPI EnumDisplaySettingsExW(LPCWSTR lpszDeviceName, DWORD iModeNum, return USER_Driver->pEnumDisplaySettingsEx(lpszDeviceName, iModeNum, lpDevMode, dwFlags); } + +static DPI_AWARENESS_CONTEXT dpi_awareness; + +/********************************************************************** + * SetProcessDpiAwarenessContext (USER32.@) + */ +BOOL WINAPI SetProcessDpiAwarenessContext( DPI_AWARENESS_CONTEXT context ) +{ + if (!IsValidDpiAwarenessContext( context )) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return FALSE; + } + if (InterlockedCompareExchangePointer( (void **)&dpi_awareness, context, NULL )) + { + SetLastError( ERROR_ACCESS_DENIED ); + return FALSE; + } + TRACE( "set to %p\n", context ); + return TRUE; +} + /*********************************************************************** * AreDpiAwarenessContextsEqual (USER32.@) */ @@ -2980,6 +3002,7 @@ BOOL WINAPI IsValidDpiAwarenessContext( DPI_AWARENESS_CONTEXT context ) BOOL WINAPI SetProcessDPIAware(void) { TRACE("\n"); + InterlockedCompareExchangePointer( (void **)&dpi_awareness, DPI_AWARENESS_CONTEXT_SYSTEM_AWARE, NULL ); return TRUE; } @@ -2988,8 +3011,8 @@ BOOL WINAPI SetProcessDPIAware(void) */ BOOL WINAPI IsProcessDPIAware(void) { - TRACE("returning TRUE\n"); - return TRUE; + /* FIXME: should default to FALSE when not set */ + return dpi_awareness != DPI_AWARENESS_CONTEXT_UNAWARE; } /*********************************************************************** diff --git a/dlls/user32/tests/sysparams.c b/dlls/user32/tests/sysparams.c index 5dd8e58ba56..03fa8d59401 100644 --- a/dlls/user32/tests/sysparams.c +++ b/dlls/user32/tests/sysparams.c @@ -41,6 +41,7 @@ static LONG (WINAPI *pChangeDisplaySettingsExA)(LPCSTR, LPDEVMODEA, HWND, DWORD, LPVOID); static BOOL (WINAPI *pIsProcessDPIAware)(void); static BOOL (WINAPI *pSetProcessDPIAware)(void); +static BOOL (WINAPI *pSetProcessDpiAwarenessContext)(DPI_AWARENESS_CONTEXT); static BOOL strict; static int dpi, real_dpi; @@ -2995,6 +2996,30 @@ static void test_dpi_aware(void) return; } + if (pSetProcessDpiAwarenessContext) + { + SetLastError( 0xdeadbeef ); + ret = pSetProcessDpiAwarenessContext( NULL ); + ok( !ret, "got %d\n", ret ); + ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + ret = pSetProcessDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)-5 ); + ok( !ret, "got %d\n", ret ); + ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() ); + ret = pSetProcessDpiAwarenessContext( DPI_AWARENESS_CONTEXT_SYSTEM_AWARE ); + ok( ret, "got %d\n", ret ); + SetLastError( 0xdeadbeef ); + ret = pSetProcessDpiAwarenessContext( DPI_AWARENESS_CONTEXT_SYSTEM_AWARE ); + ok( !ret, "got %d\n", ret ); + ok( GetLastError() == ERROR_ACCESS_DENIED, "wrong error %u\n", GetLastError() ); + SetLastError( 0xdeadbeef ); + ret = pSetProcessDpiAwarenessContext( DPI_AWARENESS_CONTEXT_UNAWARE ); + ok( !ret, "got %d\n", ret ); + ok( GetLastError() == ERROR_ACCESS_DENIED, "wrong error %u\n", GetLastError() ); + ret = pIsProcessDPIAware(); + ok(ret, "got %d\n", ret); + } + ret = pSetProcessDPIAware(); ok(ret, "got %d\n", ret); @@ -3019,6 +3044,7 @@ START_TEST(sysparams) pChangeDisplaySettingsExA = (void*)GetProcAddress(hdll, "ChangeDisplaySettingsExA"); pIsProcessDPIAware = (void*)GetProcAddress(hdll, "IsProcessDPIAware"); pSetProcessDPIAware = (void*)GetProcAddress(hdll, "SetProcessDPIAware"); + pSetProcessDpiAwarenessContext = (void*)GetProcAddress(hdll, "SetProcessDpiAwarenessContext"); hInstance = GetModuleHandleA( NULL ); hdc = GetDC(0); diff --git a/dlls/user32/user32.spec b/dlls/user32/user32.spec index f37b6a498bd..b0109cb1abc 100644 --- a/dlls/user32/user32.spec +++ b/dlls/user32/user32.spec @@ -671,8 +671,9 @@ @ stdcall SetMessageQueue(long) @ stdcall SetParent(long long) @ stdcall SetPhysicalCursorPos(long long) -@ stdcall SetProcessDefaultLayout(long) @ stdcall SetProcessDPIAware() +@ stdcall SetProcessDefaultLayout(long) +@ stdcall SetProcessDpiAwarenessContext(long) @ stdcall SetProcessWindowStation(long) @ stdcall SetProgmanWindow (long) @ stdcall SetPropA(long str long) diff --git a/include/winuser.h b/include/winuser.h index 213a83a3dcd..24d9e5709e0 100644 --- a/include/winuser.h +++ b/include/winuser.h @@ -4064,6 +4064,7 @@ WINUSERAPI HWND WINAPI SetParent(HWND,HWND); WINUSERAPI BOOL WINAPI SetPhysicalCursorPos(INT,INT); WINUSERAPI BOOL WINAPI SetProcessDPIAware(void); WINUSERAPI BOOL WINAPI SetProcessDefaultLayout(DWORD); +WINUSERAPI BOOL WINAPI SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT); WINUSERAPI BOOL WINAPI SetProcessWindowStation(HWINSTA); WINUSERAPI BOOL WINAPI SetPropA(HWND,LPCSTR,HANDLE); WINUSERAPI BOOL WINAPI SetPropW(HWND,LPCWSTR,HANDLE);