From 74a9c91964bcbc9a5d550c2059c07c307c227414 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 12 Apr 2018 13:24:36 +0200 Subject: [PATCH] user32: Get the system DPI from the registry instead of from GDI. Signed-off-by: Alexandre Julliard --- dlls/user32/sysparams.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c index 95a883d4d9e..7b948eba538 100644 --- a/dlls/user32/sysparams.c +++ b/dlls/user32/sysparams.c @@ -612,6 +612,31 @@ static BOOL init_entry_string( struct sysparam_entry *entry, const WCHAR *str ) return init_entry( entry, str, (strlenW(str) + 1) * sizeof(WCHAR), REG_SZ ); } +static DWORD get_reg_dword( HKEY base, const WCHAR *key_name, const WCHAR *value_name ) +{ + HKEY key; + DWORD type, ret = 0, size = sizeof(ret); + + if (RegOpenKeyW( base, key_name, &key )) return 0; + if (RegQueryValueExW( key, value_name, NULL, &type, (void *)&ret, &size ) || type != REG_DWORD) + ret = 0; + RegCloseKey( key ); + return ret; +} + +/* get the system dpi from the registry */ +static UINT get_system_dpi(void) +{ + static const WCHAR dpi_key_name[] = {'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\','D','e','s','k','t','o','p','\0'}; + static const WCHAR def_dpi_key_name[] = {'S','o','f','t','w','a','r','e','\\','F','o','n','t','s','\0'}; + static const WCHAR dpi_value_name[] = {'L','o','g','P','i','x','e','l','s','\0'}; + DWORD dpi; + + if ((dpi = get_reg_dword( HKEY_CURRENT_USER, dpi_key_name, dpi_value_name ))) return dpi; + if ((dpi = get_reg_dword( HKEY_CURRENT_CONFIG, def_dpi_key_name, dpi_value_name ))) return dpi; + return USER_DEFAULT_SCREEN_DPI; +} + HDC get_display_dc(void) { static const WCHAR DISPLAY[] = {'D','I','S','P','L','A','Y',0}; @@ -3065,12 +3090,7 @@ UINT WINAPI GetDpiForSystem(void) if (!IsProcessDPIAware()) return USER_DEFAULT_SCREEN_DPI; - if (!display_dpi) - { - HDC hdc = get_display_dc(); - display_dpi = GetDeviceCaps( hdc, LOGPIXELSY ); - release_display_dc( hdc ); - } + if (!display_dpi) display_dpi = get_system_dpi(); return display_dpi; } -- 2.11.4.GIT