Alexandre Julliard : user32: Set the thread DPI awareness to the window' s when calling a window procedure.
Alexandre Julliard
julliard at winehq.org
Wed May 2 15:50:02 CDT 2018
Module: wine
Branch: master
Commit: 39f0bbff4ea16e2ff674d849a38dd0c60f425f8d
URL: https://source.winehq.org/git/wine.git/?a=commit;h=39f0bbff4ea16e2ff674d849a38dd0c60f425f8d
Author: Alexandre Julliard <julliard at winehq.org>
Date: Wed May 2 17:33:19 2018 +0200
user32: Set the thread DPI awareness to the window's when calling a window procedure.
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/user.exe16/message.c | 3 +++
dlls/user32/tests/sysparams.c | 58 ++++++++++++++++++++++++-------------------
dlls/user32/winproc.c | 6 +++++
3 files changed, 42 insertions(+), 25 deletions(-)
diff --git a/dlls/user.exe16/message.c b/dlls/user.exe16/message.c
index 9e07be9..290f36b 100644
--- a/dlls/user.exe16/message.c
+++ b/dlls/user.exe16/message.c
@@ -228,6 +228,7 @@ WNDPROC16 WINPROC_GetProc16( WNDPROC proc, BOOL unicode )
static LRESULT call_window_proc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
LRESULT *result, void *arg )
{
+ DPI_AWARENESS_CONTEXT awareness;
WNDPROC16 func = arg;
int index = winproc_to_index( func );
CONTEXT context;
@@ -281,6 +282,7 @@ static LRESULT call_window_proc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPA
}
}
+ awareness = SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( HWND_32(hwnd) ));
args.params[4] = hwnd;
args.params[3] = msg;
args.params[2] = wParam;
@@ -288,6 +290,7 @@ static LRESULT call_window_proc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPA
args.params[0] = LOWORD(lParam);
WOWCallback16Ex( 0, WCB16_REGS, sizeof(args.params) + size, &args, (DWORD *)&context );
*result = MAKELONG( LOWORD(context.Eax), LOWORD(context.Edx) );
+ SetThreadDpiAwarenessContext( awareness );
return *result;
}
diff --git a/dlls/user32/tests/sysparams.c b/dlls/user32/tests/sysparams.c
index 1836ca5..9620ffa 100644
--- a/dlls/user32/tests/sysparams.c
+++ b/dlls/user32/tests/sysparams.c
@@ -3512,11 +3512,22 @@ static void test_dpi_context(void)
ReleaseDC( 0, hdc );
}
+static LRESULT CALLBACK dpi_winproc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp )
+{
+ DPI_AWARENESS_CONTEXT ctx = pGetWindowDpiAwarenessContext( hwnd );
+ DPI_AWARENESS_CONTEXT ctx2 = pGetThreadDpiAwarenessContext();
+ ok( pGetAwarenessFromDpiAwarenessContext( ctx ) == pGetAwarenessFromDpiAwarenessContext( ctx2 ),
+ "msg %04x wrong awareness %p / %p\n", msg, ctx, ctx2 );
+ return DefWindowProcA( hwnd, msg, wp, lp );
+}
+
static void test_dpi_window(void)
{
DPI_AWARENESS_CONTEXT context, orig;
DPI_AWARENESS awareness;
+ ULONG_PTR i, j;
HWND hwnd;
+ MSG msg = { 0, WM_USER + 1, 0, 0 };
if (!pGetWindowDpiAwarenessContext)
{
@@ -3524,31 +3535,25 @@ static void test_dpi_window(void)
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 = pGetWindowDpiAwarenessContext( 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 = pGetWindowDpiAwarenessContext( 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 = pGetWindowDpiAwarenessContext( hwnd );
- awareness = pGetAwarenessFromDpiAwarenessContext( context );
- ok( awareness == DPI_AWARENESS_PER_MONITOR_AWARE, "wrong awareness %u\n", awareness );
- DestroyWindow( hwnd );
+ for (i = DPI_AWARENESS_UNAWARE; i <= DPI_AWARENESS_PER_MONITOR_AWARE; i++)
+ {
+ pSetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)~i );
+ hwnd = CreateWindowA( "DpiTestClass", "Test",
+ WS_OVERLAPPEDWINDOW, 0, 0, 100, 100, 0, 0, GetModuleHandleA(0), NULL );
+ ok( hwnd != 0, "failed to create window\n" );
+ context = pGetWindowDpiAwarenessContext( hwnd );
+ awareness = pGetAwarenessFromDpiAwarenessContext( context );
+ ok( awareness == i, "%lu: wrong awareness %u\n", i, awareness );
+ msg.hwnd = hwnd;
+ for (j = DPI_AWARENESS_UNAWARE; j <= DPI_AWARENESS_PER_MONITOR_AWARE; j++)
+ {
+ pSetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)~j );
+ SendMessageA( hwnd, WM_USER, 0, 0 );
+ DispatchMessageA( &msg );
+ CallWindowProcA( dpi_winproc, hwnd, WM_USER + 2, 0, 0 );
+ }
+ DestroyWindow( hwnd );
+ }
SetLastError( 0xdeadbeef );
context = pGetWindowDpiAwarenessContext( (HWND)0xdeadbeef );
@@ -3634,6 +3639,9 @@ START_TEST(sysparams)
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
RegisterClassA( &wc );
+ wc.lpszClassName = "DpiTestClass";
+ wc.lpfnWndProc = dpi_winproc;
+ RegisterClassA( &wc );
ghTestWnd = CreateWindowA( "SysParamsTestClass", "Test System Parameters Application",
WS_OVERLAPPEDWINDOW, 0, 0, 100, 100, 0, 0, hInstance, NULL );
diff --git a/dlls/user32/winproc.c b/dlls/user32/winproc.c
index e07971c..b2d4fd2 100644
--- a/dlls/user32/winproc.c
+++ b/dlls/user32/winproc.c
@@ -233,6 +233,7 @@ static WPARAM map_wparam_char_WtoA( WPARAM wParam, DWORD len )
/* call a 32-bit window procedure */
static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp, LRESULT *result, void *arg )
{
+ DPI_AWARENESS_CONTEXT context;
WNDPROC proc = arg;
USER_CheckNotLock();
@@ -241,7 +242,9 @@ static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp, LRES
TRACE_(relay)( "\1Call window proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
proc, hwnd, SPY_GetMsgName(msg, hwnd), wp, lp );
+ context = SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( hwnd ));
*result = WINPROC_wrapper( proc, hwnd, msg, wp, lp );
+ SetThreadDpiAwarenessContext( context );
TRACE_(relay)( "\1Ret window proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx) retval=%08lx\n",
proc, hwnd, SPY_GetMsgName(msg, hwnd), wp, lp, *result );
@@ -251,6 +254,7 @@ static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp, LRES
/* call a 32-bit dialog procedure */
static LRESULT call_dialog_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp, LRESULT *result, void *arg )
{
+ DPI_AWARENESS_CONTEXT context;
WNDPROC proc = arg;
LRESULT ret;
@@ -260,8 +264,10 @@ static LRESULT call_dialog_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp, LRES
TRACE_(relay)( "\1Call dialog proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
proc, hwnd, SPY_GetMsgName(msg, hwnd), wp, lp );
+ context = SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( hwnd ));
ret = WINPROC_wrapper( proc, hwnd, msg, wp, lp );
*result = GetWindowLongPtrW( hwnd, DWLP_MSGRESULT );
+ SetThreadDpiAwarenessContext( context );
TRACE_(relay)( "\1Ret dialog proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx) retval=%08lx result=%08lx\n",
proc, hwnd, SPY_GetMsgName(msg, hwnd), wp, lp, ret, *result );
More information about the wine-cvs
mailing list