Jacek Caban : win32u: Move GetDpiForWindow from user32.

Alexandre Julliard julliard at winehq.org
Wed Mar 9 16:08:44 CST 2022


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Mar  9 15:22:07 2022 +0100

win32u: Move GetDpiForWindow from user32.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/user32/win.c            | 30 +-----------------------------
 dlls/win32u/sysparams.c      |  9 +++++++++
 dlls/win32u/win32u_private.h |  1 +
 dlls/win32u/window.c         | 36 ++++++++++++++++++++++++++++++++++++
 include/ntuser.h             |  1 +
 5 files changed, 48 insertions(+), 29 deletions(-)

diff --git a/dlls/user32/win.c b/dlls/user32/win.c
index 48541c19a66..98396293912 100644
--- a/dlls/user32/win.c
+++ b/dlls/user32/win.c
@@ -2099,35 +2099,7 @@ DPI_AWARENESS_CONTEXT WINAPI GetWindowDpiAwarenessContext( HWND hwnd )
  */
 UINT WINAPI GetDpiForWindow( HWND hwnd )
 {
-    WND *win;
-    UINT ret = 0;
-
-    if (!(win = WIN_GetPtr( hwnd )))
-    {
-        SetLastError( ERROR_INVALID_WINDOW_HANDLE );
-        return 0;
-    }
-    if (win == WND_DESKTOP)
-    {
-        POINT pt = { 0, 0 };
-        return get_monitor_dpi( MonitorFromPoint( pt, MONITOR_DEFAULTTOPRIMARY ));
-    }
-    if (win != WND_OTHER_PROCESS)
-    {
-        ret = win->dpi;
-        if (!ret) ret = get_win_monitor_dpi( hwnd );
-        WIN_ReleasePtr( win );
-    }
-    else
-    {
-        SERVER_START_REQ( get_window_info )
-        {
-            req->handle = wine_server_user_handle( hwnd );
-            if (!wine_server_call_err( req )) ret = reply->dpi;
-        }
-        SERVER_END_REQ;
-    }
-    return ret;
+    return NtUserCallHwnd( hwnd, NtUserGetDpiForWindow );
 }
 
 
diff --git a/dlls/win32u/sysparams.c b/dlls/win32u/sysparams.c
index c1a5470d9c1..3bcc2df007a 100644
--- a/dlls/win32u/sysparams.c
+++ b/dlls/win32u/sysparams.c
@@ -1379,6 +1379,15 @@ UINT get_monitor_dpi( HMONITOR monitor )
     return system_dpi;
 }
 
+/**********************************************************************
+ *              get_win_monitor_dpi
+ */
+UINT get_win_monitor_dpi( HWND hwnd )
+{
+    /* FIXME: use the monitor DPI instead */
+    return system_dpi;
+}
+
 /**********************************************************************
  *           get_thread_dpi_awareness
  */
diff --git a/dlls/win32u/win32u_private.h b/dlls/win32u/win32u_private.h
index 131e177a397..42426a512f0 100644
--- a/dlls/win32u/win32u_private.h
+++ b/dlls/win32u/win32u_private.h
@@ -284,6 +284,7 @@ extern LRESULT send_message( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
 /* sysparams.c */
 extern RECT get_display_rect( const WCHAR *display ) DECLSPEC_HIDDEN;
 extern UINT get_monitor_dpi( HMONITOR monitor ) DECLSPEC_HIDDEN;
+extern UINT get_win_monitor_dpi( HWND hwnd ) DECLSPEC_HIDDEN;
 extern UINT get_system_dpi(void) DECLSPEC_HIDDEN;
 extern int get_system_metrics( int index ) DECLSPEC_HIDDEN;
 extern UINT get_thread_dpi(void) DECLSPEC_HIDDEN;
diff --git a/dlls/win32u/window.c b/dlls/win32u/window.c
index ce03df84994..8aa794421d2 100644
--- a/dlls/win32u/window.c
+++ b/dlls/win32u/window.c
@@ -708,6 +708,40 @@ static DPI_AWARENESS_CONTEXT get_window_dpi_awareness_context( HWND hwnd )
     return ret;
 }
 
+/* see GetDpiForWindow */
+static UINT get_dpi_for_window( HWND hwnd )
+{
+    WND *win;
+    UINT ret = 0;
+
+    if (!(win = get_win_ptr( hwnd )))
+    {
+        SetLastError( ERROR_INVALID_WINDOW_HANDLE );
+        return 0;
+    }
+    if (win == WND_DESKTOP)
+    {
+        POINT pt = { 0, 0 };
+        return get_monitor_dpi( monitor_from_point( pt, MONITOR_DEFAULTTOPRIMARY, 0 ));
+    }
+    if (win != WND_OTHER_PROCESS)
+    {
+        ret = win->dpi;
+        if (!ret) ret = get_win_monitor_dpi( hwnd );
+        release_win_ptr( win );
+    }
+    else
+    {
+        SERVER_START_REQ( get_window_info )
+        {
+            req->handle = wine_server_user_handle( hwnd );
+            if (!wine_server_call_err( req )) ret = reply->dpi;
+        }
+        SERVER_END_REQ;
+    }
+    return ret;
+}
+
 static LONG_PTR get_win_data( const void *ptr, UINT size )
 {
     if (size == sizeof(WORD))
@@ -1115,6 +1149,8 @@ ULONG_PTR WINAPI NtUserCallHwnd( HWND hwnd, DWORD code )
 {
     switch (code)
     {
+    case NtUserGetDpiForWindow:
+        return get_dpi_for_window( hwnd );
     case NtUserGetParent:
         return HandleToUlong( get_parent( hwnd ));
     case NtUserGetWindowDpiAwarenessContext:
diff --git a/include/ntuser.h b/include/ntuser.h
index f45d0e8641c..20c8c2876f0 100644
--- a/include/ntuser.h
+++ b/include/ntuser.h
@@ -141,6 +141,7 @@ enum
 /* NtUserCallHwnd codes, not compatible with Windows */
 enum
 {
+    NtUserGetDpiForWindow,
     NtUserGetParent,
     NtUserGetWindowDpiAwarenessContext,
     NtUserGetWindowTextLength,




More information about the wine-cvs mailing list