Alexandre Julliard : user32: Implement Get/SetThreadDpiAwarenessContext().

Alexandre Julliard julliard at winehq.org
Mon Apr 2 16:32:52 CDT 2018


Module: wine
Branch: master
Commit: 478814ed95cdbb2aa89ef0af0903fd88dd10195c
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=478814ed95cdbb2aa89ef0af0903fd88dd10195c

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Mon Apr  2 12:48:29 2018 +0200

user32: Implement Get/SetThreadDpiAwarenessContext().

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/user32/sysparams.c       | 23 +++++++++++++++++++++--
 dlls/user32/tests/sysparams.c | 40 ++++++++++++++++++++++++++++++++++++++++
 dlls/user32/user32.spec       |  1 +
 dlls/user32/user_private.h    |  1 +
 include/winuser.h             |  1 +
 5 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c
index 7780293..a018dfc 100644
--- a/dlls/user32/sysparams.c
+++ b/dlls/user32/sysparams.c
@@ -3042,12 +3042,31 @@ UINT WINAPI GetDpiForWindow( HWND hwnd )
 }
 
 /**********************************************************************
+ *              GetThreadDpiAwarenessContext   (USER32.@)
+ */
+DPI_AWARENESS_CONTEXT WINAPI GetThreadDpiAwarenessContext(void)
+{
+    struct user_thread_info *info = get_user_thread_info();
+
+    if (info->dpi_awareness) return info->dpi_awareness;
+    if (dpi_awareness) return dpi_awareness;
+    return DPI_AWARENESS_CONTEXT_SYSTEM_AWARE;  /* FIXME: should default to unaware */
+}
+
+/**********************************************************************
  *              SetThreadDpiAwarenessContext   (USER32.@)
  */
 DPI_AWARENESS_CONTEXT WINAPI SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT context )
 {
-    FIXME("(%p): stub\n", context);
-    return NULL;
+    DPI_AWARENESS_CONTEXT prev = GetThreadDpiAwarenessContext();
+
+    if (!IsValidDpiAwarenessContext( context ))
+    {
+        SetLastError( ERROR_INVALID_PARAMETER );
+        return 0;
+    }
+    get_user_thread_info()->dpi_awareness = context;
+    return prev;
 }
 
 /**********************************************************************
diff --git a/dlls/user32/tests/sysparams.c b/dlls/user32/tests/sysparams.c
index 03fa8d5..b541be4 100644
--- a/dlls/user32/tests/sysparams.c
+++ b/dlls/user32/tests/sysparams.c
@@ -42,6 +42,9 @@ static LONG (WINAPI *pChangeDisplaySettingsExA)(LPCSTR, LPDEVMODEA, HWND, DWORD,
 static BOOL (WINAPI *pIsProcessDPIAware)(void);
 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 (WINAPI *pGetAwarenessFromDpiAwarenessContext)(DPI_AWARENESS_CONTEXT);
 
 static BOOL strict;
 static int dpi, real_dpi;
@@ -2998,6 +3001,13 @@ static void test_dpi_aware(void)
 
     if (pSetProcessDpiAwarenessContext)
     {
+        DPI_AWARENESS awareness;
+        DPI_AWARENESS_CONTEXT context;
+
+        context = pGetThreadDpiAwarenessContext();
+        awareness = pGetAwarenessFromDpiAwarenessContext( context );
+        todo_wine
+        ok( awareness == DPI_AWARENESS_UNAWARE, "wrong awareness %u\n", awareness );
         SetLastError( 0xdeadbeef );
         ret = pSetProcessDpiAwarenessContext( NULL );
         ok( !ret, "got %d\n", ret );
@@ -3018,7 +3028,34 @@ static void test_dpi_aware(void)
         ok( GetLastError() == ERROR_ACCESS_DENIED, "wrong error %u\n", GetLastError() );
         ret = pIsProcessDPIAware();
         ok(ret, "got %d\n", ret);
+        context = pGetThreadDpiAwarenessContext();
+        awareness = pGetAwarenessFromDpiAwarenessContext( context );
+        ok( awareness == DPI_AWARENESS_SYSTEM_AWARE, "wrong awareness %u\n", awareness );
+        SetLastError( 0xdeadbeef );
+        context = pSetThreadDpiAwarenessContext( 0 );
+        ok( !context, "got %p\n", context );
+        ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
+        SetLastError( 0xdeadbeef );
+        context = pSetThreadDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)-5 );
+        ok( !context, "got %p\n", context );
+        ok( GetLastError() == ERROR_INVALID_PARAMETER, "wrong error %u\n", GetLastError() );
+        context = pSetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_UNAWARE );
+        awareness = pGetAwarenessFromDpiAwarenessContext( context );
+        ok( awareness == DPI_AWARENESS_SYSTEM_AWARE, "wrong awareness %u\n", awareness );
+        context = pGetThreadDpiAwarenessContext();
+        awareness = pGetAwarenessFromDpiAwarenessContext( context );
+        ok( awareness == DPI_AWARENESS_UNAWARE, "wrong awareness %u\n", awareness );
+        context = pSetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE );
+        awareness = pGetAwarenessFromDpiAwarenessContext( context );
+        ok( awareness == DPI_AWARENESS_UNAWARE, "wrong awareness %u\n", awareness );
+        context = pGetThreadDpiAwarenessContext();
+        awareness = pGetAwarenessFromDpiAwarenessContext( context );
+        ok( awareness == DPI_AWARENESS_PER_MONITOR_AWARE, "wrong awareness %u\n", awareness );
+        context = pSetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_SYSTEM_AWARE );
+        awareness = pGetAwarenessFromDpiAwarenessContext( context );
+        ok( awareness == DPI_AWARENESS_PER_MONITOR_AWARE, "wrong awareness %u\n", awareness );
     }
+    else win_skip( "SetProcessDPIAware not supported\n" );
 
     ret = pSetProcessDPIAware();
     ok(ret, "got %d\n", ret);
@@ -3045,6 +3082,9 @@ START_TEST(sysparams)
     pIsProcessDPIAware = (void*)GetProcAddress(hdll, "IsProcessDPIAware");
     pSetProcessDPIAware = (void*)GetProcAddress(hdll, "SetProcessDPIAware");
     pSetProcessDpiAwarenessContext = (void*)GetProcAddress(hdll, "SetProcessDpiAwarenessContext");
+    pGetThreadDpiAwarenessContext = (void*)GetProcAddress(hdll, "GetThreadDpiAwarenessContext");
+    pSetThreadDpiAwarenessContext = (void*)GetProcAddress(hdll, "SetThreadDpiAwarenessContext");
+    pGetAwarenessFromDpiAwarenessContext = (void*)GetProcAddress(hdll, "GetAwarenessFromDpiAwarenessContext");
 
     hInstance = GetModuleHandleA( NULL );
     hdc = GetDC(0);
diff --git a/dlls/user32/user32.spec b/dlls/user32/user32.spec
index b0109cb..85499b6 100644
--- a/dlls/user32/user32.spec
+++ b/dlls/user32/user32.spec
@@ -379,6 +379,7 @@
 @ stdcall GetTabbedTextExtentW(long wstr long long ptr)
 @ stdcall GetTaskmanWindow ()
 @ stdcall GetThreadDesktop(long)
+@ stdcall GetThreadDpiAwarenessContext()
 @ stdcall GetTitleBarInfo(long ptr)
 @ stdcall GetTopWindow(long)
 @ stdcall GetTouchInputInfo(long long ptr long)
diff --git a/dlls/user32/user_private.h b/dlls/user32/user_private.h
index 5d54cb1..7d33d9d 100644
--- a/dlls/user32/user_private.h
+++ b/dlls/user32/user_private.h
@@ -169,6 +169,7 @@ struct wm_char_mapping_data
 /* no attempt is made to keep the layout compatible with the Windows one */
 struct user_thread_info
 {
+    DPI_AWARENESS_CONTEXT         dpi_awareness;          /* DPI awareness context */
     HANDLE                        server_queue;           /* Handle to server-side queue */
     DWORD                         wake_mask;              /* Current queue wake mask */
     DWORD                         changed_mask;           /* Current queue changed mask */
diff --git a/include/winuser.h b/include/winuser.h
index 24d9e57..31ab49e 100644
--- a/include/winuser.h
+++ b/include/winuser.h
@@ -3766,6 +3766,7 @@ WINUSERAPI DWORD       WINAPI GetTabbedTextExtentW(HDC,LPCWSTR,INT,INT,const INT
 #define                       GetTabbedTextExtent WINELIB_NAME_AW(GetTabbedTextExtent)
 WINUSERAPI BOOL        WINAPI GetTitleBarInfo(HWND,PTITLEBARINFO);
 WINUSERAPI HDESK       WINAPI GetThreadDesktop(DWORD);
+WINUSERAPI DPI_AWARENESS_CONTEXT WINAPI GetThreadDpiAwarenessContext(void);
 WINUSERAPI HWND        WINAPI GetTopWindow(HWND);
 WINUSERAPI BOOL        WINAPI GetTouchInputInfo(HTOUCHINPUT,UINT,TOUCHINPUT*,int);
 WINUSERAPI BOOL        WINAPI GetUpdateRect(HWND,LPRECT,BOOL);




More information about the wine-cvs mailing list