From 3f97ba3f463dfad41274f0bd64865267227d6b10 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Mon, 2 Apr 2018 13:28:20 +0200 Subject: [PATCH] user32: Partially implement GetWindowDpiAwarenessContext(). Signed-off-by: Alexandre Julliard --- dlls/user32/tests/sysparams.c | 60 +++++++++++++++++++++++++++++++++++++++++++ dlls/user32/user32.spec | 1 + dlls/user32/win.c | 27 +++++++++++++++++++ dlls/user32/win.h | 1 + include/winuser.h | 1 + 5 files changed, 90 insertions(+) diff --git a/dlls/user32/tests/sysparams.c b/dlls/user32/tests/sysparams.c index b541be4e133..876f84ffb0f 100644 --- a/dlls/user32/tests/sysparams.c +++ b/dlls/user32/tests/sysparams.c @@ -44,6 +44,7 @@ static BOOL (WINAPI *pSetProcessDPIAware)(void); static BOOL (WINAPI *pSetProcessDpiAwarenessContext)(DPI_AWARENESS_CONTEXT); static DPI_AWARENESS_CONTEXT (WINAPI *pGetThreadDpiAwarenessContext)(void); static DPI_AWARENESS_CONTEXT (WINAPI *pSetThreadDpiAwarenessContext)(DPI_AWARENESS_CONTEXT); +static DPI_AWARENESS_CONTEXT (WINAPI *pGetWindowDpiAwarenessContext)(HWND); static DPI_AWARENESS (WINAPI *pGetAwarenessFromDpiAwarenessContext)(DPI_AWARENESS_CONTEXT); static BOOL strict; @@ -3067,6 +3068,63 @@ static void test_dpi_aware(void) test_GetSystemMetrics(); } +static void test_window_dpi(void) +{ + DPI_AWARENESS_CONTEXT context, orig; + DPI_AWARENESS awareness; + HWND hwnd; + + if (!pGetWindowDpiAwarenessContext) + { + win_skip( "GetWindowDpiAwarenessContext not supported\n" ); + return; + } + orig = pSetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_UNAWARE ); + hwnd = CreateWindowA( "SysParamsTestClass", "Test System Parameters Application", + WS_OVERLAPPEDWINDOW, 0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL ); + ok( hwnd != 0, "failed to create window\n" ); + context = GetWindowDpiAwarenessContext( hwnd ); + awareness = pGetAwarenessFromDpiAwarenessContext( context ); + ok( awareness == DPI_AWARENESS_UNAWARE, "wrong awareness %u\n", awareness ); + DestroyWindow( hwnd ); + + pSetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_SYSTEM_AWARE ); + hwnd = CreateWindowA( "SysParamsTestClass", "Test System Parameters Application", + WS_OVERLAPPEDWINDOW, 0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL ); + ok( hwnd != 0, "failed to create window\n" ); + context = GetWindowDpiAwarenessContext( hwnd ); + awareness = pGetAwarenessFromDpiAwarenessContext( context ); + ok( awareness == DPI_AWARENESS_SYSTEM_AWARE, "wrong awareness %u\n", awareness ); + DestroyWindow( hwnd ); + + pSetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE ); + hwnd = CreateWindowA( "SysParamsTestClass", "Test System Parameters Application", + WS_OVERLAPPEDWINDOW, 0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL ); + ok( hwnd != 0, "failed to create window\n" ); + context = GetWindowDpiAwarenessContext( hwnd ); + awareness = pGetAwarenessFromDpiAwarenessContext( context ); + ok( awareness == DPI_AWARENESS_PER_MONITOR_AWARE, "wrong awareness %u\n", awareness ); + DestroyWindow( hwnd ); + + SetLastError( 0xdeadbeef ); + context = GetWindowDpiAwarenessContext( (HWND)0xdeadbeef ); + ok( !context, "got %p\n", context ); + ok( GetLastError() == ERROR_INVALID_WINDOW_HANDLE, "wrong error %u\n", GetLastError() ); + + SetLastError( 0xdeadbeef ); + context = GetWindowDpiAwarenessContext( GetDesktopWindow() ); + awareness = pGetAwarenessFromDpiAwarenessContext( context ); + ok( awareness == DPI_AWARENESS_PER_MONITOR_AWARE, "wrong awareness %u\n", awareness ); + + pSetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_UNAWARE ); + SetLastError( 0xdeadbeef ); + context = GetWindowDpiAwarenessContext( GetDesktopWindow() ); + awareness = pGetAwarenessFromDpiAwarenessContext( context ); + ok( awareness == DPI_AWARENESS_PER_MONITOR_AWARE, "wrong awareness %u\n", awareness ); + + pSetThreadDpiAwarenessContext( orig ); +} + START_TEST(sysparams) { int argc; @@ -3084,6 +3142,7 @@ START_TEST(sysparams) pSetProcessDpiAwarenessContext = (void*)GetProcAddress(hdll, "SetProcessDpiAwarenessContext"); pGetThreadDpiAwarenessContext = (void*)GetProcAddress(hdll, "GetThreadDpiAwarenessContext"); pSetThreadDpiAwarenessContext = (void*)GetProcAddress(hdll, "SetThreadDpiAwarenessContext"); + pGetWindowDpiAwarenessContext = (void*)GetProcAddress(hdll, "GetWindowDpiAwarenessContext"); pGetAwarenessFromDpiAwarenessContext = (void*)GetProcAddress(hdll, "GetAwarenessFromDpiAwarenessContext"); hInstance = GetModuleHandleA( NULL ); @@ -3136,4 +3195,5 @@ START_TEST(sysparams) ReleaseDC( 0, hdc); test_dpi_aware(); + test_window_dpi(); } diff --git a/dlls/user32/user32.spec b/dlls/user32/user32.spec index 85499b6456f..d407a18f73c 100644 --- a/dlls/user32/user32.spec +++ b/dlls/user32/user32.spec @@ -394,6 +394,7 @@ @ stdcall GetWindowContextHelpId(long) @ stdcall GetWindowDC(long) @ stdcall GetWindowDisplayAffinity(long ptr) +@ stdcall GetWindowDpiAwarenessContext(long) @ stdcall GetWindowInfo(long ptr) @ stdcall GetWindowLongA(long long) @ stdcall -arch=win64 GetWindowLongPtrA(long long) diff --git a/dlls/user32/win.c b/dlls/user32/win.c index 019b178f957..02725662b55 100644 --- a/dlls/user32/win.c +++ b/dlls/user32/win.c @@ -1498,6 +1498,7 @@ HWND WIN_CreateWindowEx( CREATESTRUCTW *cs, LPCWSTR className, HINSTANCE module, wndPtr->hIconSmall = 0; wndPtr->hIconSmall2 = 0; wndPtr->hSysMenu = 0; + wndPtr->dpi_awareness = GetThreadDpiAwarenessContext(); wndPtr->min_pos.x = wndPtr->min_pos.y = -1; wndPtr->max_pos.x = wndPtr->max_pos.y = -1; @@ -2215,6 +2216,32 @@ BOOL WINAPI IsWindowUnicode( HWND hwnd ) } +/*********************************************************************** + * GetWindowDpiAwarenessContext (USER32.@) + */ +DPI_AWARENESS_CONTEXT WINAPI GetWindowDpiAwarenessContext( HWND hwnd ) +{ + WND *win; + DPI_AWARENESS_CONTEXT ret; + + if (!(win = WIN_GetPtr( hwnd ))) + { + SetLastError( ERROR_INVALID_WINDOW_HANDLE ); + return 0; + } + if (win == WND_DESKTOP) return DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE; + if (win == WND_OTHER_PROCESS) + { + if (IsWindow( hwnd )) FIXME( "not supported on other process window %p\n", hwnd ); + else SetLastError( ERROR_INVALID_WINDOW_HANDLE ); + return 0; + } + ret = win->dpi_awareness; + WIN_ReleasePtr( win ); + return ret; +} + + /********************************************************************** * WIN_GetWindowLong * diff --git a/dlls/user32/win.h b/dlls/user32/win.h index f728d1936b6..0c7fcc86384 100644 --- a/dlls/user32/win.h +++ b/dlls/user32/win.h @@ -61,6 +61,7 @@ typedef struct tagWND HICON hIcon; /* window's icon */ HICON hIconSmall; /* window's small icon */ HICON hIconSmall2; /* window's secondary small icon, derived from hIcon */ + DPI_AWARENESS_CONTEXT dpi_awareness; /* DPI awareness context */ struct window_surface *surface; /* Window surface if any */ struct tagDIALOGINFO *dlgInfo;/* Dialog additional info (dialogs only) */ int pixel_format; /* Pixel format set by the graphics driver */ diff --git a/include/winuser.h b/include/winuser.h index 31ab49eefb5..63cfd5ce311 100644 --- a/include/winuser.h +++ b/include/winuser.h @@ -3780,6 +3780,7 @@ WINUSERAPI HWND WINAPI GetWindow(HWND,UINT); WINUSERAPI DWORD WINAPI GetWindowContextHelpId(HWND); WINUSERAPI HDC WINAPI GetWindowDC(HWND); WINUSERAPI BOOL WINAPI GetWindowDisplayAffinity(HWND,DWORD*); +WINUSERAPI DPI_AWARENESS_CONTEXT WINAPI GetWindowDpiAwarenessContext(HWND); WINUSERAPI BOOL WINAPI GetWindowInfo(HWND, PWINDOWINFO); WINUSERAPI LONG WINAPI GetWindowLongA(HWND,INT); WINUSERAPI LONG WINAPI GetWindowLongW(HWND,INT); -- 2.11.4.GIT