user32: Partially implement GetWindowDpiAwarenessContext().

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
oldstable
Alexandre Julliard 2018-04-02 13:28:20 +02:00
parent 478814ed95
commit 3f97ba3f46
5 changed files with 90 additions and 0 deletions

View File

@ -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();
}

View File

@ -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)

View File

@ -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
*

View File

@ -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 */

View File

@ -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);