Alexandre Julliard : user32: Scale coordinates in Get/SetWindowPlacement() based on DPI awareness.

Alexandre Julliard julliard at winehq.org
Fri Aug 24 13:59:15 CDT 2018


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

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Fri Aug 24 12:23:28 2018 +0200

user32: Scale coordinates in Get/SetWindowPlacement() based on DPI awareness.

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

---

 dlls/user32/sysparams.c | 20 ++++++++++++++++++++
 dlls/user32/win.h       |  3 +++
 dlls/user32/winpos.c    | 12 ++++++------
 3 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c
index a971062..9d7c256 100644
--- a/dlls/user32/sysparams.c
+++ b/dlls/user32/sysparams.c
@@ -3245,6 +3245,16 @@ POINT point_win_to_thread_dpi( HWND hwnd, POINT pt )
 }
 
 /**********************************************************************
+ *              point_thread_to_win_dpi
+ */
+POINT point_thread_to_win_dpi( HWND hwnd, POINT pt )
+{
+    UINT dpi = get_thread_dpi();
+    if (!dpi) dpi = get_win_monitor_dpi( hwnd );
+    return map_dpi_point( pt, dpi, GetDpiForWindow( hwnd ));
+}
+
+/**********************************************************************
  *              map_dpi_rect
  */
 RECT map_dpi_rect( RECT rect, UINT dpi_from, UINT dpi_to )
@@ -3270,6 +3280,16 @@ RECT rect_win_to_thread_dpi( HWND hwnd, RECT rect )
 }
 
 /**********************************************************************
+ *              rect_thread_to_win_dpi
+ */
+RECT rect_thread_to_win_dpi( HWND hwnd, RECT rect )
+{
+    UINT dpi = get_thread_dpi();
+    if (!dpi) dpi = get_win_monitor_dpi( hwnd );
+    return map_dpi_rect( rect, dpi, GetDpiForWindow( hwnd ) );
+}
+
+/**********************************************************************
  *              SetProcessDpiAwarenessContext   (USER32.@)
  */
 BOOL WINAPI SetProcessDpiAwarenessContext( DPI_AWARENESS_CONTEXT context )
diff --git a/dlls/user32/win.h b/dlls/user32/win.h
index b912ef8..f30b004 100644
--- a/dlls/user32/win.h
+++ b/dlls/user32/win.h
@@ -133,8 +133,11 @@ extern UINT get_win_monitor_dpi( HWND hwnd ) DECLSPEC_HIDDEN;
 extern UINT get_thread_dpi(void) DECLSPEC_HIDDEN;
 extern POINT map_dpi_point( POINT pt, UINT dpi_from, UINT dpi_to ) DECLSPEC_HIDDEN;
 extern POINT point_win_to_thread_dpi( HWND hwnd, POINT pt ) DECLSPEC_HIDDEN;
+extern POINT point_thread_to_win_dpi( HWND hwnd, POINT pt ) DECLSPEC_HIDDEN;
 extern RECT map_dpi_rect( RECT rect, UINT dpi_from, UINT dpi_to ) DECLSPEC_HIDDEN;
 extern RECT rect_win_to_thread_dpi( HWND hwnd, RECT rect ) DECLSPEC_HIDDEN;
+extern RECT rect_thread_to_win_dpi( HWND hwnd, RECT rect ) DECLSPEC_HIDDEN;
+
 extern BOOL set_window_pos( HWND hwnd, HWND insert_after, UINT swp_flags,
                             const RECT *window_rect, const RECT *client_rect,
                             const RECT *valid_rects ) DECLSPEC_HIDDEN;
diff --git a/dlls/user32/winpos.c b/dlls/user32/winpos.c
index 1dd9c12..98eec62 100644
--- a/dlls/user32/winpos.c
+++ b/dlls/user32/winpos.c
@@ -1342,9 +1342,9 @@ BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
         wndpl->flags = WPF_RESTORETOMAXIMIZED;
     else
         wndpl->flags = 0;
-    wndpl->ptMinPosition    = pWnd->min_pos;
-    wndpl->ptMaxPosition    = pWnd->max_pos;
-    wndpl->rcNormalPosition = pWnd->normal_rect;
+    wndpl->ptMinPosition = EMPTYPOINT(pWnd->min_pos) ? pWnd->min_pos : point_win_to_thread_dpi( hwnd, pWnd->min_pos );
+    wndpl->ptMaxPosition = EMPTYPOINT(pWnd->max_pos) ? pWnd->max_pos : point_win_to_thread_dpi( hwnd, pWnd->max_pos );
+    wndpl->rcNormalPosition = rect_win_to_thread_dpi( hwnd, pWnd->normal_rect );
     WIN_ReleasePtr( pWnd );
 
     TRACE( "%p: returning min %d,%d max %d,%d normal %s\n",
@@ -1419,9 +1419,9 @@ static BOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, UINT f
 
     if (!pWnd || pWnd == WND_OTHER_PROCESS || pWnd == WND_DESKTOP) return FALSE;
 
-    if( flags & PLACE_MIN ) pWnd->min_pos = wp.ptMinPosition;
-    if( flags & PLACE_MAX ) pWnd->max_pos = wp.ptMaxPosition;
-    if( flags & PLACE_RECT) pWnd->normal_rect = wp.rcNormalPosition;
+    if (flags & PLACE_MIN) pWnd->min_pos = point_thread_to_win_dpi( hwnd, wp.ptMinPosition );
+    if (flags & PLACE_MAX) pWnd->max_pos = point_thread_to_win_dpi( hwnd, wp.ptMaxPosition );
+    if (flags & PLACE_RECT) pWnd->normal_rect = rect_thread_to_win_dpi( hwnd, wp.rcNormalPosition );
 
     style = pWnd->dwStyle;
 




More information about the wine-cvs mailing list