[UXTHEME] Implement SetSystemVisualStyle (#7864)

Implement SetSystemVisualStyle based on function and flags found at https://stackoverflow.com/a/1036903 and 
https://pinvoke.net/default.aspx/uxtheme.SetSystemVisualStyle
This commit is contained in:
Whindmar Saksit 2025-06-21 18:56:48 +02:00 committed by GitHub
parent 99b99bda0f
commit e307cad501
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 82 additions and 15 deletions

View file

@ -438,6 +438,19 @@ ApplyScheme(IN COLOR_SCHEME *scheme, IN PTHEME_SELECTION pSelectedTheme)
StyleName, StyleName,
(lstrlenW(StyleName) + 1) * sizeof(WCHAR)); (lstrlenW(StyleName) + 1) * sizeof(WCHAR));
} }
if (pSelectedTheme->ThemeActive)
{
SHSetValueW(HKEY_CURRENT_USER, L"Control Panel\\Appearance", L"Current", REG_SZ, NULL, 0);
SHSetValueW(HKEY_CURRENT_USER, L"Control Panel\\Appearance", L"NewCurrent", REG_SZ, NULL, 0);
}
else if (pSelectedTheme->Color)
{
PCWSTR ClassicSchemeName = pSelectedTheme->Color->DisplayName;
DWORD cb = (lstrlenW(ClassicSchemeName) + 1) * sizeof(WCHAR);
SHSetValueW(HKEY_CURRENT_USER, L"Control Panel\\Appearance", L"Current", REG_SZ, ClassicSchemeName, cb); // 95+
SHSetValueW(HKEY_CURRENT_USER, L"Control Panel\\Appearance", L"NewCurrent", REG_SZ, ClassicSchemeName, cb); // XP+
}
} }
static THEME* static THEME*

View file

@ -545,12 +545,21 @@ static HRESULT UXTHEME_ApplyTheme(PTHEME_FILE tf)
(lstrlenW(tf->pszSelectedSize)+1)*sizeof(WCHAR)); (lstrlenW(tf->pszSelectedSize)+1)*sizeof(WCHAR));
RegSetValueExW(hKey, szDllName, 0, REG_SZ, (const BYTE*)tf->szThemeFile, RegSetValueExW(hKey, szDllName, 0, REG_SZ, (const BYTE*)tf->szThemeFile,
(lstrlenW(tf->szThemeFile)+1)*sizeof(WCHAR)); (lstrlenW(tf->szThemeFile)+1)*sizeof(WCHAR));
#ifdef __REACTOS__
{
WCHAR buf[sizeof("4294967295")];
UINT cch = wsprintfW(buf, L"%u", GetUserDefaultUILanguage());
RegSetValueExW(hKey, L"LastUserLangID", 0, REG_SZ, (const BYTE*)buf, ++cch * sizeof(WCHAR));
}
#endif
} }
else { else {
RegDeleteValueW(hKey, szColorName); RegDeleteValueW(hKey, szColorName);
RegDeleteValueW(hKey, szSizeName); RegDeleteValueW(hKey, szSizeName);
RegDeleteValueW(hKey, szDllName); RegDeleteValueW(hKey, szDllName);
#ifdef __REACTOS__
RegDeleteValueW(hKey, L"LastUserLangID");
#endif
} }
RegCloseKey(hKey); RegCloseKey(hKey);
} }
@ -1215,32 +1224,62 @@ HRESULT WINAPI CloseThemeFile(HTHEMEFILE hThemeFile)
* *
* PARAMS * PARAMS
* hThemeFile Handle to theme file * hThemeFile Handle to theme file
* unknown See notes * Flags Unknown flag bits
* hWnd Window requesting the theme change * hWnd Window requesting the theme change
* *
* RETURNS * RETURNS
* Success: S_OK * Success: S_OK
* Failure: HRESULT error-code * Failure: HRESULT error-code
*
* NOTES
* I'm not sure what the second parameter is (the datatype is likely wrong), other then this:
* Under XP if I pass
* char b[] = "";
* the theme is applied with the screen redrawing really badly (flickers)
* char b[] = "\0"; where \0 can be one or more of any character, makes no difference
* the theme is applied smoothly (screen does not flicker)
* char *b = "\0" or NULL; where \0 can be zero or more of any character, makes no difference
* the function fails returning invalid parameter... very strange
*/ */
#ifdef __REACTOS__
HRESULT WINAPI ApplyTheme(HTHEMEFILE hThemeFile, UINT Flags, HWND hWnd)
#else
HRESULT WINAPI ApplyTheme(HTHEMEFILE hThemeFile, char *unknown, HWND hWnd) HRESULT WINAPI ApplyTheme(HTHEMEFILE hThemeFile, char *unknown, HWND hWnd)
#endif
{ {
HRESULT hr; HRESULT hr;
#ifdef __REACTOS__
TRACE("(%p,%#x,%p)\n", hThemeFile, Flags, hWnd);
#else
TRACE("(%p,%s,%p)\n", hThemeFile, unknown, hWnd); TRACE("(%p,%s,%p)\n", hThemeFile, unknown, hWnd);
#endif
hr = UXTHEME_ApplyTheme(hThemeFile); hr = UXTHEME_ApplyTheme(hThemeFile);
UXTHEME_broadcast_theme_changed (NULL, (g_ActiveThemeFile != NULL)); UXTHEME_broadcast_theme_changed (NULL, (g_ActiveThemeFile != NULL));
return hr; return hr;
} }
#ifdef __REACTOS__
/**********************************************************************
* SetSystemVisualStyle (UXTHEME.65)
*/
HRESULT WINAPI SetSystemVisualStyle(PCWSTR pszStyleFile, PCWSTR pszColor, PCWSTR pszSize, UINT Flags)
{
PTHEME_FILE pThemeFile = NULL;
HRESULT hr;
if (pszStyleFile)
{
if (!g_bThemeHooksActive)
return E_FAIL;
if (pszColor && !*pszColor)
pszColor = NULL;
if (pszSize && !*pszSize)
pszSize = NULL;
hr = MSSTYLES_OpenThemeFile(pszStyleFile, pszColor, pszSize, &pThemeFile);
if (FAILED(hr))
return hr;
}
hr = ApplyTheme(pThemeFile, Flags, NULL);
if (pThemeFile)
MSSTYLES_CloseThemeFile(pThemeFile);
return hr;
}
#endif // __REACTOS__
/********************************************************************** /**********************************************************************
* GetThemeDefaults (UXTHEME.7) * GetThemeDefaults (UXTHEME.7)
* *
@ -1273,8 +1312,15 @@ HRESULT WINAPI GetThemeDefaults(LPCWSTR pszThemeFileName, LPWSTR pszColorName,
hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt); hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt);
if(FAILED(hr)) return hr; if(FAILED(hr)) return hr;
#ifdef __REACTOS__
if (pszColorName)
lstrcpynW(pszColorName, pt->pszSelectedColor, dwColorNameLen);
if (pszSizeName)
lstrcpynW(pszSizeName, pt->pszSelectedSize, dwSizeNameLen);
#else
lstrcpynW(pszColorName, pt->pszSelectedColor, dwColorNameLen); lstrcpynW(pszColorName, pt->pszSelectedColor, dwColorNameLen);
lstrcpynW(pszSizeName, pt->pszSelectedSize, dwSizeNameLen); lstrcpynW(pszSizeName, pt->pszSelectedSize, dwSizeNameLen);
#endif
MSSTYLES_CloseThemeFile(pt); MSSTYLES_CloseThemeFile(pt);
return S_OK; return S_OK;

View file

@ -62,7 +62,7 @@
62 stub -noname ServerClearStockObjects 62 stub -noname ServerClearStockObjects
63 stub -noname MarkSelection 63 stub -noname MarkSelection
#64 ProcessLoadTheme_RunDLLW #64 ProcessLoadTheme_RunDLLW
#65 SetSystemVisualStyle 65 stdcall -noname SetSystemVisualStyle(wstr wstr wstr long)
#66 ServiceClearStockObjects #66 ServiceClearStockObjects
67 stdcall GetThemeIntList(ptr long long long ptr) 67 stdcall GetThemeIntList(ptr long long long ptr)
68 stdcall GetThemeMargins(ptr ptr long long long ptr ptr) 68 stdcall GetThemeMargins(ptr ptr long long long ptr ptr)

View file

@ -62,7 +62,7 @@
62 stub -noname ServerClearStockObjects 62 stub -noname ServerClearStockObjects
63 stub -noname MarkSelection 63 stub -noname MarkSelection
64 stub ProcessLoadTheme_RunDLLW 64 stub ProcessLoadTheme_RunDLLW
65 stub SetSystemVisualStyle 65 stdcall -noname SetSystemVisualStyle(wstr wstr wstr long)
66 stub ServiceClearStockObjects 66 stub ServiceClearStockObjects
67 stdcall -stub AddThemeAppCompatFlag(ptr long long long ptr) 67 stdcall -stub AddThemeAppCompatFlag(ptr long long long ptr)
68 stdcall -stub ResetThemeAppCompatFlags(ptr ptr long long long ptr ptr) 68 stdcall -stub ResetThemeAppCompatFlags(ptr ptr long long long ptr ptr)

View file

@ -81,10 +81,18 @@ HRESULT WINAPI OpenThemeFile(LPCWSTR pszThemeFileName,
HRESULT WINAPI CloseThemeFile(HTHEMEFILE hThemeFile); HRESULT WINAPI CloseThemeFile(HTHEMEFILE hThemeFile);
#define UXTAPPLYFLAG_LOADSYSTEMMETRICS 0x01 // https://stackoverflow.com/a/1036903
#define UXTAPPLYFLAG_APPLYSYSTEMMETRICS 0x20 // https://stackoverflow.com/a/1036903
HRESULT WINAPI ApplyTheme(HTHEMEFILE hThemeFile, HRESULT WINAPI ApplyTheme(HTHEMEFILE hThemeFile,
char *unknown, UINT Flags,
HWND hWnd); HWND hWnd);
HRESULT WINAPI SetSystemVisualStyle(PCWSTR pszStyleFile,
PCWSTR pszColor,
PCWSTR pszSize,
UINT Flags);
HRESULT WINAPI GetThemeDefaults(LPCWSTR pszThemeFileName, HRESULT WINAPI GetThemeDefaults(LPCWSTR pszThemeFileName,
LPWSTR pszColorName, LPWSTR pszColorName,
DWORD dwColorNameLen, DWORD dwColorNameLen,