From 92f5c6e410fe0dbcbfa4aae708e7afd9564efb21 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 23 Aug 2018 12:23:47 +0200 Subject: [PATCH] user32: Scale monitor rectangles based on DPI awareness. Signed-off-by: Alexandre Julliard --- dlls/user32/sysparams.c | 26 +++++++++++++++++++++++++- dlls/user32/win.h | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c index 10f90a25262..b6679c5deba 100644 --- a/dlls/user32/sysparams.c +++ b/dlls/user32/sysparams.c @@ -3221,6 +3221,21 @@ UINT get_thread_dpi(void) } } +/********************************************************************** + * map_dpi_rect + */ +RECT map_dpi_rect( RECT rect, UINT dpi_from, UINT dpi_to ) +{ + if (dpi_from && dpi_to && dpi_from != dpi_to) + { + rect.left = MulDiv( rect.left, dpi_to, dpi_from ); + rect.top = MulDiv( rect.top, dpi_to, dpi_from ); + rect.right = MulDiv( rect.right, dpi_to, dpi_from ); + rect.bottom = MulDiv( rect.bottom, dpi_to, dpi_from ); + } + return rect; +} + /********************************************************************** * SetProcessDpiAwarenessContext (USER32.@) */ @@ -3586,13 +3601,22 @@ BOOL WINAPI GetMonitorInfoA( HMONITOR monitor, LPMONITORINFO info ) BOOL WINAPI GetMonitorInfoW( HMONITOR monitor, LPMONITORINFO info ) { BOOL ret; + UINT dpi_from, dpi_to; if (info->cbSize != sizeof(MONITORINFOEXW) && info->cbSize != sizeof(MONITORINFO)) return FALSE; ret = USER_Driver->pGetMonitorInfo( monitor, info ); if (ret) + { + if ((dpi_to = get_thread_dpi())) + { + dpi_from = get_monitor_dpi( monitor ); + info->rcMonitor = map_dpi_rect( info->rcMonitor, dpi_from, dpi_to ); + info->rcWork = map_dpi_rect( info->rcWork, dpi_from, dpi_to ); + } TRACE( "flags %04x, monitor %s, work %s\n", info->dwFlags, wine_dbgstr_rect(&info->rcMonitor), wine_dbgstr_rect(&info->rcWork)); + } return ret; } @@ -3634,7 +3658,7 @@ __ASM_GLOBAL_FUNC( enum_mon_callback_wrapper, static BOOL CALLBACK enum_mon_callback( HMONITOR monitor, HDC hdc, LPRECT rect, LPARAM lp ) { struct enum_mon_data *data = (struct enum_mon_data *)lp; - RECT monrect = *rect; + RECT monrect = map_dpi_rect( *rect, get_monitor_dpi( monitor ), get_thread_dpi() ); OffsetRect( &monrect, -data->origin.x, -data->origin.y ); if (!IntersectRect( &monrect, &monrect, &data->limit )) return TRUE; diff --git a/dlls/user32/win.h b/dlls/user32/win.h index f9e11ffab89..226e3e9c00a 100644 --- a/dlls/user32/win.h +++ b/dlls/user32/win.h @@ -131,6 +131,7 @@ extern void WINPOS_SysCommandSizeMove( HWND hwnd, WPARAM wParam ) DECLSPEC_HIDDE extern UINT get_monitor_dpi( HMONITOR monitor ) DECLSPEC_HIDDEN; extern UINT get_win_monitor_dpi( HWND hwnd ) DECLSPEC_HIDDEN; extern UINT get_thread_dpi(void) DECLSPEC_HIDDEN; +extern RECT map_dpi_rect( RECT rect, UINT dpi_from, UINT dpi_to ) 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;