/********************************************************************** * ApplyTheme (UXTHEME.4) * * Set a theme file to be the currently active theme * * PARAMS * hThemeFile Handle to theme file * unknown See notes * hWnd Window requesting the theme change * * RETURNS * Success: S_OK * 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 */ HRESULT WINAPI ApplyTheme(HTHEMEFILE hThemeFile, char *unknown, HWND hWnd) { HRESULT hr; TRACE("(%p,%s,%p)\n", hThemeFile, unknown, hWnd); hr = UXTHEME_SetActiveTheme(hThemeFile); UXTHEME_broadcast_msg (NULL, WM_THEMECHANGED); return hr; }
/*********************************************************************** * UXTHEME_ApplyTheme * * Change the current active theme */ static HRESULT UXTHEME_ApplyTheme(PTHEME_FILE tf) { HKEY hKey; WCHAR tmp[2]; HRESULT hr; TRACE("UXTHEME_ApplyTheme\n"); if (tf && !ActiveThemeFile) { UXTHEME_BackupSystemMetrics(); } hr = UXTHEME_SetActiveTheme(tf); if (FAILED(hr)) return hr; if (!tf) { UXTHEME_RestoreSystemMetrics(); } TRACE("Writing theme config to registry\n"); if(!RegCreateKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) { tmp[0] = ActiveThemeFile?'1':'0'; tmp[1] = '\0'; RegSetValueExW(hKey, szThemeActive, 0, REG_SZ, (const BYTE*)tmp, sizeof(WCHAR)*2); if (ActiveThemeFile) { RegSetValueExW(hKey, szColorName, 0, REG_SZ, (const BYTE*)tf->pszSelectedColor, (lstrlenW(tf->pszSelectedColor)+1)*sizeof(WCHAR)); RegSetValueExW(hKey, szSizeName, 0, REG_SZ, (const BYTE*)tf->pszSelectedSize, (lstrlenW(tf->pszSelectedSize)+1)*sizeof(WCHAR)); RegSetValueExW(hKey, szDllName, 0, REG_SZ, (const BYTE*)tf->szThemeFile, (lstrlenW(tf->szThemeFile)+1)*sizeof(WCHAR)); } else { RegDeleteValueW(hKey, szColorName); RegDeleteValueW(hKey, szSizeName); RegDeleteValueW(hKey, szDllName); } RegCloseKey(hKey); } else TRACE("Failed to open theme registry key\n"); UXTHEME_SaveSystemMetrics (); return hr; }
/*********************************************************************** * UXTHEME_LoadTheme * * Set the current active theme from the registry */ void UXTHEME_LoadTheme(BOOL bLoad) { HKEY hKey; DWORD buffsize; HRESULT hr; WCHAR tmp[10]; PTHEME_FILE pt; WCHAR szCurrentTheme[MAX_PATH]; WCHAR szCurrentColor[64]; WCHAR szCurrentSize[64]; BOOL bThemeActive = FALSE; if(bLoad == TRUE) { /* Get current theme configuration */ if(!RegOpenKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) { TRACE("Loading theme config\n"); buffsize = sizeof(tmp)/sizeof(tmp[0]); if(!RegQueryValueExW(hKey, szThemeActive, NULL, NULL, (LPBYTE)tmp, &buffsize)) { bThemeActive = (tmp[0] != '0'); } else { bThemeActive = FALSE; TRACE("Failed to get ThemeActive: %d\n", GetLastError()); } buffsize = sizeof(szCurrentColor)/sizeof(szCurrentColor[0]); if(RegQueryValueExW(hKey, szColorName, NULL, NULL, (LPBYTE)szCurrentColor, &buffsize)) szCurrentColor[0] = '\0'; buffsize = sizeof(szCurrentSize)/sizeof(szCurrentSize[0]); if(RegQueryValueExW(hKey, szSizeName, NULL, NULL, (LPBYTE)szCurrentSize, &buffsize)) szCurrentSize[0] = '\0'; if (query_reg_path (hKey, szDllName, szCurrentTheme)) szCurrentTheme[0] = '\0'; RegCloseKey(hKey); } else TRACE("Failed to open theme registry key\n"); } else { bThemeActive = FALSE; } if(bThemeActive) { /* Make sure the theme requested is actually valid */ hr = MSSTYLES_OpenThemeFile(szCurrentTheme, szCurrentColor[0]?szCurrentColor:NULL, szCurrentSize[0]?szCurrentSize:NULL, &pt); if(FAILED(hr)) { bThemeActive = FALSE; } else { TRACE("Theme active: %s %s %s\n", debugstr_w(szCurrentTheme), debugstr_w(szCurrentColor), debugstr_w(szCurrentSize)); UXTHEME_SetActiveTheme(pt); MSSTYLES_CloseThemeFile(pt); } } if(!bThemeActive) { UXTHEME_SetActiveTheme(NULL); TRACE("Theming not active\n"); } }