From c044cff4c7a98741ebc1b47ca3624828eb088968 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Fri, 10 Mar 2023 16:29:42 -0800 Subject: [PATCH] Rewrite WIN_GetSystemTheme() so we don't need to bump Windows SDK versions --- src/core/windows/SDL_windows.h | 2 +- src/video/windows/SDL_windowsvideo.c | 25 +++++++++++++------------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/core/windows/SDL_windows.h b/src/core/windows/SDL_windows.h index 62db3ff00..386e426dc 100644 --- a/src/core/windows/SDL_windows.h +++ b/src/core/windows/SDL_windows.h @@ -41,7 +41,7 @@ #elif defined(HAVE_SHELLSCALINGAPI_H) #define _WIN32_WINNT 0x603 /* For DPI support */ #else -#define _WIN32_WINNT 0x502 /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices(), 0x501 for raw input, 0x502 for RegGetValue() */ +#define _WIN32_WINNT 0x501 /* Need 0x410 for AlphaBlend() and 0x500 for EnumDisplayDevices(), 0x501 for raw input */ #endif #define WINVER _WIN32_WINNT diff --git a/src/video/windows/SDL_windowsvideo.c b/src/video/windows/SDL_windowsvideo.c index 0a9200c95..71d38300f 100644 --- a/src/video/windows/SDL_windowsvideo.c +++ b/src/video/windows/SDL_windowsvideo.c @@ -680,21 +680,22 @@ SDL_bool SDL_DXGIGetOutputInfo(SDL_DisplayID displayID, int *adapterIndex, int * SDL_SystemTheme WIN_GetSystemTheme(void) { - DWORD type; - DWORD value; - DWORD count = sizeof(value); - LSTATUS status; + SDL_SystemTheme theme = SDL_SYSTEM_THEME_LIGHT; + HKEY hKey; + DWORD dwType = REG_DWORD; + DWORD value = ~0; + DWORD length = sizeof(value); /* Technically this isn't the system theme, but it's the preference for applications */ - status = RegGetValue(HKEY_CURRENT_USER, - TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize"), - TEXT("AppsUseLightTheme"), - RRF_RT_REG_DWORD, &type, &value, &count); - if (status == ERROR_SUCCESS && type == REG_DWORD && value == 0) { - return SDL_SYSTEM_THEME_DARK; - } else { - return SDL_SYSTEM_THEME_LIGHT; + if (RegOpenKeyExW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", 0, KEY_READ, &hKey) == ERROR_SUCCESS) { + if (RegQueryValueExW(hKey, L"AppsUseLightTheme", 0, &dwType, (LPBYTE)&value, &length) == ERROR_SUCCESS) { + if (value == 0) { + theme = SDL_SYSTEM_THEME_DARK; + } + } + RegCloseKey(hKey); } + return theme; } SDL_bool WIN_IsPerMonitorV2DPIAware(_THIS)