From: Rémi Bernon rbernon@codeweavers.com
Making sure it only executes after system_dpi is initialized. Otherwise SetProcessDpiAwarenessContext calls will fail to translate system DPI aware context aliases to the NTUSER_DPI_CONTEXT values with explicit system DPI values. --- dlls/user32/sysparams.c | 48 ++++++++++++++++++++++++++++++++++ dlls/user32/user_main.c | 57 ----------------------------------------- 2 files changed, 48 insertions(+), 57 deletions(-)
diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c index 273dccc6930..cc459f39572 100644 --- a/dlls/user32/sysparams.c +++ b/dlls/user32/sysparams.c @@ -161,7 +161,55 @@ void release_display_dc( HDC hdc ) */ void SYSPARAMS_Init(void) { + WCHAR buffer[256]; + DWORD option; + system_dpi = NtUserGetSystemDpiForProcess( NULL ); + + if (!LdrQueryImageFileExecutionOptions( &NtCurrentTeb()->Peb->ProcessParameters->ImagePathName, + L"dpiAwareness", REG_DWORD, &option, sizeof(option), NULL )) + { + TRACE( "got option %lx\n", option ); + if (option <= 2) + { + SetProcessDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)~(ULONG_PTR)option ); + return; + } + } + + if (QueryActCtxSettingsW( 0, NULL, L"http://schemas.microsoft.com/SMI/2016/WindowsSettings", + L"dpiAwareness", buffer, ARRAY_SIZE(buffer), NULL )) + { + static const WCHAR * const types[] = { L"unaware", L"system", L"permonitor", L"permonitorv2" }; + WCHAR *p, *start, *end; + ULONG_PTR i; + + TRACE( "got dpiAwareness=%s\n", debugstr_w(buffer) ); + for (start = buffer; *start; start = end) + { + start += wcsspn( start, L" \t\r\n" ); + if (!(end = wcschr( start, ',' ))) end = start + lstrlenW(start); + else *end++ = 0; + if ((p = wcspbrk( start, L" \t\r\n" ))) *p = 0; + for (i = 0; i < ARRAY_SIZE(types); i++) + { + if (wcsicmp( start, types[i] )) continue; + SetProcessDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)~i ); + return; + } + } + } + else if (QueryActCtxSettingsW( 0, NULL, L"http://schemas.microsoft.com/SMI/2005/WindowsSettings", + L"dpiAware", buffer, ARRAY_SIZE(buffer), NULL )) + { + TRACE( "got dpiAware=%s\n", debugstr_w(buffer) ); + if (!wcsicmp( buffer, L"true" )) + SetProcessDpiAwarenessContext( DPI_AWARENESS_CONTEXT_SYSTEM_AWARE ); + else if (!wcsicmp( buffer, L"true/pm" ) || !wcsicmp( buffer, L"per monitor" )) + SetProcessDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE ); + else + SetProcessDpiAwarenessContext( DPI_AWARENESS_CONTEXT_UNAWARE ); + } }
static BOOL update_desktop_wallpaper(void) diff --git a/dlls/user32/user_main.c b/dlls/user32/user_main.c index 03b88c07bed..20b3fa8b1f6 100644 --- a/dlls/user32/user_main.c +++ b/dlls/user32/user_main.c @@ -44,62 +44,6 @@ UINT WINAPI UserRealizePalette( HDC hdc ) }
-/*********************************************************************** - * dpiaware_init - * - * Initialize the DPI awareness style. - */ -static void dpiaware_init(void) -{ - WCHAR buffer[256]; - DWORD option; - - if (!LdrQueryImageFileExecutionOptions( &NtCurrentTeb()->Peb->ProcessParameters->ImagePathName, - L"dpiAwareness", REG_DWORD, &option, sizeof(option), NULL )) - { - TRACE( "got option %lx\n", option ); - if (option <= 2) - { - SetProcessDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)~(ULONG_PTR)option ); - return; - } - } - - if (QueryActCtxSettingsW( 0, NULL, L"http://schemas.microsoft.com/SMI/2016/WindowsSettings", - L"dpiAwareness", buffer, ARRAY_SIZE(buffer), NULL )) - { - static const WCHAR * const types[] = { L"unaware", L"system", L"permonitor", L"permonitorv2" }; - WCHAR *p, *start, *end; - ULONG_PTR i; - - TRACE( "got dpiAwareness=%s\n", debugstr_w(buffer) ); - for (start = buffer; *start; start = end) - { - start += wcsspn( start, L" \t\r\n" ); - if (!(end = wcschr( start, ',' ))) end = start + lstrlenW(start); - else *end++ = 0; - if ((p = wcspbrk( start, L" \t\r\n" ))) *p = 0; - for (i = 0; i < ARRAY_SIZE(types); i++) - { - if (wcsicmp( start, types[i] )) continue; - SetProcessDpiAwarenessContext( (DPI_AWARENESS_CONTEXT)~i ); - return; - } - } - } - else if (QueryActCtxSettingsW( 0, NULL, L"http://schemas.microsoft.com/SMI/2005/WindowsSettings", - L"dpiAware", buffer, ARRAY_SIZE(buffer), NULL )) - { - TRACE( "got dpiAware=%s\n", debugstr_w(buffer) ); - if (!wcsicmp( buffer, L"true" )) - SetProcessDpiAwarenessContext( DPI_AWARENESS_CONTEXT_SYSTEM_AWARE ); - else if (!wcsicmp( buffer, L"true/pm" ) || !wcsicmp( buffer, L"per monitor" )) - SetProcessDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE ); - else - SetProcessDpiAwarenessContext( DPI_AWARENESS_CONTEXT_UNAWARE ); - } -} - static NTSTATUS WINAPI User32CopyImage( void *args, ULONG size ) { const struct copy_image_params *params = args; @@ -255,7 +199,6 @@ static BOOL process_attach(void) NtCurrentTeb()->Peb->KernelCallbackTable = kernel_callback_table;
winproc_init(); - dpiaware_init(); SYSPARAMS_Init();
return TRUE;