Alexandre Julliard : user32: Take DPI awareness into account in GetDpiForMonitorInternal().
Alexandre Julliard
julliard at winehq.org
Tue Jul 17 15:52:37 CDT 2018
Module: wine
Branch: master
Commit: 898f4b6c6a20cc3800bd38142da1d02d5a6a948e
URL: https://source.winehq.org/git/wine.git/?a=commit;h=898f4b6c6a20cc3800bd38142da1d02d5a6a948e
Author: Alexandre Julliard <julliard at winehq.org>
Date: Tue Jul 17 13:54:40 2018 +0200
user32: Take DPI awareness into account in GetDpiForMonitorInternal().
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/user32/sysparams.c | 34 +++++++++++++++++++++++++++-------
dlls/user32/tests/sysparams.c | 22 ++++++++++++++++++++++
dlls/user32/win.c | 8 ++++++--
dlls/user32/win.h | 3 ++-
4 files changed, 57 insertions(+), 10 deletions(-)
diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c
index e1044e94..c92d9af 100644
--- a/dlls/user32/sysparams.c
+++ b/dlls/user32/sysparams.c
@@ -39,6 +39,7 @@
#include "winerror.h"
#include "controls.h"
+#include "win.h"
#include "user_private.h"
#include "wine/gdi_driver.h"
#include "wine/unicode.h"
@@ -3192,7 +3193,16 @@ BOOL WINAPI EnumDisplaySettingsExW(LPCWSTR lpszDeviceName, DWORD iModeNum,
/**********************************************************************
* get_monitor_dpi
*/
-UINT get_monitor_dpi( HWND hwnd )
+UINT get_monitor_dpi( HMONITOR monitor )
+{
+ /* FIXME: use the monitor DPI instead */
+ return system_dpi;
+}
+
+/**********************************************************************
+ * get_win_monitor_dpi
+ */
+UINT get_win_monitor_dpi( HWND hwnd )
{
/* FIXME: use the monitor DPI instead */
return system_dpi;
@@ -3324,12 +3334,22 @@ UINT WINAPI GetDpiForSystem(void)
*/
BOOL WINAPI GetDpiForMonitorInternal( HMONITOR monitor, UINT type, UINT *x, UINT *y )
{
- UINT dpi = system_dpi;
-
- WARN( "(%p, %u, %p, %p): semi-stub\n", monitor, type, x, y );
-
- if (x) *x = dpi;
- if (y) *y = dpi;
+ if (type > 2)
+ {
+ SetLastError( ERROR_BAD_ARGUMENTS );
+ return FALSE;
+ }
+ if (!x || !y)
+ {
+ SetLastError( ERROR_INVALID_ADDRESS );
+ return FALSE;
+ }
+ switch (GetAwarenessFromDpiAwarenessContext( GetThreadDpiAwarenessContext() ))
+ {
+ case DPI_AWARENESS_UNAWARE: *x = *y = USER_DEFAULT_SCREEN_DPI; break;
+ case DPI_AWARENESS_SYSTEM_AWARE: *x = *y = system_dpi; break;
+ default: *x = *y = get_monitor_dpi( monitor ); break;
+ }
return TRUE;
}
diff --git a/dlls/user32/tests/sysparams.c b/dlls/user32/tests/sysparams.c
index fec37b6..7903c9a 100644
--- a/dlls/user32/tests/sysparams.c
+++ b/dlls/user32/tests/sysparams.c
@@ -46,6 +46,7 @@ static BOOL (WINAPI *pGetProcessDpiAwarenessInternal)(HANDLE,DPI_AWARENESS*);
static BOOL (WINAPI *pSetProcessDpiAwarenessInternal)(DPI_AWARENESS);
static UINT (WINAPI *pGetDpiForSystem)(void);
static UINT (WINAPI *pGetDpiForWindow)(HWND);
+static BOOL (WINAPI *pGetDpiForMonitorInternal)(HMONITOR,UINT,UINT*,UINT*);
static DPI_AWARENESS_CONTEXT (WINAPI *pGetThreadDpiAwarenessContext)(void);
static DPI_AWARENESS_CONTEXT (WINAPI *pSetThreadDpiAwarenessContext)(DPI_AWARENESS_CONTEXT);
static DPI_AWARENESS_CONTEXT (WINAPI *pGetWindowDpiAwarenessContext)(HWND);
@@ -3549,6 +3550,26 @@ static void test_dpi_window(void)
dpi = pGetDpiForWindow( hwnd );
ok( dpi == (i == DPI_AWARENESS_UNAWARE ? USER_DEFAULT_SCREEN_DPI : real_dpi),
"%lu: got %u / %u\n", i, dpi, real_dpi );
+ if (pGetDpiForMonitorInternal)
+ {
+ BOOL res;
+ SetLastError( 0xdeadbeef );
+ res = pGetDpiForMonitorInternal( MonitorFromWindow( hwnd, 0 ), 0, &dpi, NULL );
+ ok( !res, "succeeded\n" );
+ ok( GetLastError() == ERROR_INVALID_ADDRESS, "wrong error %u\n", GetLastError() );
+ SetLastError( 0xdeadbeef );
+ res = pGetDpiForMonitorInternal( MonitorFromWindow( hwnd, 0 ), 3, &dpi, &dpi );
+ ok( !res, "succeeded\n" );
+ ok( GetLastError() == ERROR_BAD_ARGUMENTS, "wrong error %u\n", GetLastError() );
+ SetLastError( 0xdeadbeef );
+ res = pGetDpiForMonitorInternal( MonitorFromWindow( hwnd, 0 ), 3, &dpi, NULL );
+ ok( !res, "succeeded\n" );
+ ok( GetLastError() == ERROR_BAD_ARGUMENTS, "wrong error %u\n", GetLastError() );
+ res = pGetDpiForMonitorInternal( MonitorFromWindow( hwnd, 0 ), 0, &dpi, &dpi );
+ ok( res, "failed err %u\n", GetLastError() );
+ ok( dpi == (i == DPI_AWARENESS_UNAWARE ? USER_DEFAULT_SCREEN_DPI : real_dpi),
+ "%lu: got %u / %u\n", i, dpi, real_dpi );
+ }
msg.hwnd = hwnd;
for (j = DPI_AWARENESS_UNAWARE; j <= DPI_AWARENESS_PER_MONITOR_AWARE; j++)
{
@@ -3660,6 +3681,7 @@ START_TEST(sysparams)
pSetProcessDPIAware = (void*)GetProcAddress(hdll, "SetProcessDPIAware");
pGetDpiForSystem = (void*)GetProcAddress(hdll, "GetDpiForSystem");
pGetDpiForWindow = (void*)GetProcAddress(hdll, "GetDpiForWindow");
+ pGetDpiForMonitorInternal = (void*)GetProcAddress(hdll, "GetDpiForMonitorInternal");
pSetProcessDpiAwarenessContext = (void*)GetProcAddress(hdll, "SetProcessDpiAwarenessContext");
pGetProcessDpiAwarenessInternal = (void*)GetProcAddress(hdll, "GetProcessDpiAwarenessInternal");
pSetProcessDpiAwarenessInternal = (void*)GetProcAddress(hdll, "SetProcessDpiAwarenessInternal");
diff --git a/dlls/user32/win.c b/dlls/user32/win.c
index 28bc1f6..5f2ac4e 100644
--- a/dlls/user32/win.c
+++ b/dlls/user32/win.c
@@ -2240,11 +2240,15 @@ UINT WINAPI GetDpiForWindow( HWND hwnd )
SetLastError( ERROR_INVALID_WINDOW_HANDLE );
return 0;
}
- if (win == WND_DESKTOP) return get_monitor_dpi( GetDesktopWindow() );
+ 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_monitor_dpi( hwnd );
+ if (!ret) ret = get_win_monitor_dpi( hwnd );
WIN_ReleasePtr( win );
}
else
diff --git a/dlls/user32/win.h b/dlls/user32/win.h
index 15331c3..b6c162a 100644
--- a/dlls/user32/win.h
+++ b/dlls/user32/win.h
@@ -128,7 +128,8 @@ extern void WINPOS_ActivateOtherWindow( HWND hwnd ) DECLSPEC_HIDDEN;
extern UINT WINPOS_MinMaximize( HWND hwnd, UINT cmd, LPRECT rect ) DECLSPEC_HIDDEN;
extern void WINPOS_SysCommandSizeMove( HWND hwnd, WPARAM wParam ) DECLSPEC_HIDDEN;
-extern UINT get_monitor_dpi( HWND hwnd ) DECLSPEC_HIDDEN;
+extern UINT get_monitor_dpi( HMONITOR monitor ) DECLSPEC_HIDDEN;
+extern UINT get_win_monitor_dpi( HWND hwnd ) 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;
More information about the wine-cvs
mailing list