uxtheme: Add stub for RefreshImmersiveColorPolicyState.
[wine.git] / dlls / uxtheme / system.c
blobadf90a12cfb75da17e7933ea0a14ca58db727046
1 /*
2 * Win32 5.1 Theme system
4 * Copyright (C) 2003 Kevin Koltzau
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <stdio.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wingdi.h"
27 #include "winuser.h"
28 #include "winreg.h"
29 #include "vfwmsgs.h"
30 #include "uxtheme.h"
31 #include "vssym32.h"
33 #include "uxthemedll.h"
34 #include "msstyles.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(uxtheme);
40 /***********************************************************************
41 * Defines and global variables
44 static const WCHAR szThemeManager[] = L"Software\\Microsoft\\Windows\\CurrentVersion\\ThemeManager";
46 ATOM atDialogThemeEnabled;
48 static DWORD dwThemeAppProperties = STAP_ALLOW_NONCLIENT | STAP_ALLOW_CONTROLS;
49 static ATOM atWindowTheme;
50 static ATOM atSubAppName;
51 static ATOM atSubIdList;
53 static BOOL bThemeActive = FALSE;
54 static WCHAR szCurrentTheme[MAX_PATH];
55 static WCHAR szCurrentColor[64];
56 static WCHAR szCurrentSize[64];
58 struct user_api_hook user_api = {0};
60 /***********************************************************************/
62 static BOOL CALLBACK UXTHEME_broadcast_msg_enumchild (HWND hWnd, LPARAM msg)
64 PostMessageW(hWnd, msg, 0, 0);
65 return TRUE;
68 /* Broadcast a message to *all* windows, including children */
69 static BOOL CALLBACK UXTHEME_broadcast_msg (HWND hWnd, LPARAM msg)
71 if (hWnd == NULL)
73 EnumWindows (UXTHEME_broadcast_msg, msg);
75 else
77 PostMessageW(hWnd, msg, 0, 0);
78 EnumChildWindows (hWnd, UXTHEME_broadcast_msg_enumchild, msg);
80 return TRUE;
83 /* At the end of the day this is a subset of what SHRegGetPath() does - copied
84 * here to avoid linking against shlwapi. */
85 static DWORD query_reg_path (HKEY hKey, LPCWSTR lpszValue,
86 LPVOID pvData)
88 DWORD dwRet, dwType, dwUnExpDataLen = MAX_PATH * sizeof(WCHAR), dwExpDataLen;
90 TRACE("(hkey=%p,%s,%p)\n", hKey, debugstr_w(lpszValue),
91 pvData);
93 dwRet = RegQueryValueExW(hKey, lpszValue, 0, &dwType, pvData, &dwUnExpDataLen);
94 if (dwRet!=ERROR_SUCCESS && dwRet!=ERROR_MORE_DATA)
95 return dwRet;
97 if (dwType == REG_EXPAND_SZ)
99 DWORD nBytesToAlloc;
101 /* Expand type REG_EXPAND_SZ into REG_SZ */
102 LPWSTR szData;
104 /* If the caller didn't supply a buffer or the buffer is too small we have
105 * to allocate our own
107 if (dwRet == ERROR_MORE_DATA)
109 WCHAR emptyW[] = L"";
110 nBytesToAlloc = dwUnExpDataLen;
112 szData = LocalAlloc(LMEM_ZEROINIT, nBytesToAlloc);
113 RegQueryValueExW (hKey, lpszValue, 0, NULL, (LPBYTE)szData, &nBytesToAlloc);
114 dwExpDataLen = ExpandEnvironmentStringsW(szData, emptyW, 1);
115 dwUnExpDataLen = max(nBytesToAlloc, dwExpDataLen);
116 LocalFree(szData);
118 else
120 nBytesToAlloc = (lstrlenW(pvData) + 1) * sizeof(WCHAR);
121 szData = LocalAlloc(LMEM_ZEROINIT, nBytesToAlloc );
122 lstrcpyW(szData, pvData);
123 dwExpDataLen = ExpandEnvironmentStringsW(szData, pvData, MAX_PATH );
124 if (dwExpDataLen > MAX_PATH) dwRet = ERROR_MORE_DATA;
125 dwUnExpDataLen = max(nBytesToAlloc, dwExpDataLen);
126 LocalFree(szData);
130 return dwRet;
133 /***********************************************************************
134 * UXTHEME_LoadTheme
136 * Set the current active theme from the registry
138 static void UXTHEME_LoadTheme(void)
140 HKEY hKey;
141 DWORD buffsize;
142 HRESULT hr;
143 WCHAR tmp[10];
144 PTHEME_FILE pt;
146 /* Get current theme configuration */
147 if(!RegOpenKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
148 TRACE("Loading theme config\n");
149 buffsize = sizeof(tmp);
150 if (!RegQueryValueExW(hKey, L"ThemeActive", NULL, NULL, (BYTE*)tmp, &buffsize)) {
151 bThemeActive = (tmp[0] != '0');
153 else {
154 bThemeActive = FALSE;
155 TRACE("Failed to get ThemeActive: %ld\n", GetLastError());
157 buffsize = sizeof(szCurrentColor);
158 if (RegQueryValueExW(hKey, L"ColorName", NULL, NULL, (BYTE*)szCurrentColor, &buffsize))
159 szCurrentColor[0] = '\0';
160 buffsize = sizeof(szCurrentSize);
161 if (RegQueryValueExW(hKey, L"SizeName", NULL, NULL, (BYTE*)szCurrentSize, &buffsize))
162 szCurrentSize[0] = '\0';
163 if (query_reg_path (hKey, L"DllName", szCurrentTheme))
164 szCurrentTheme[0] = '\0';
165 RegCloseKey(hKey);
167 else
168 TRACE("Failed to open theme registry key\n");
170 if(bThemeActive) {
171 /* Make sure the theme requested is actually valid */
172 hr = MSSTYLES_OpenThemeFile(szCurrentTheme,
173 szCurrentColor[0]?szCurrentColor:NULL,
174 szCurrentSize[0]?szCurrentSize:NULL,
175 &pt);
176 if(FAILED(hr)) {
177 bThemeActive = FALSE;
178 szCurrentTheme[0] = '\0';
179 szCurrentColor[0] = '\0';
180 szCurrentSize[0] = '\0';
182 else {
183 /* Make sure the global color & size match the theme */
184 lstrcpynW(szCurrentColor, pt->pszSelectedColor, ARRAY_SIZE(szCurrentColor));
185 lstrcpynW(szCurrentSize, pt->pszSelectedSize, ARRAY_SIZE(szCurrentSize));
187 UXTHEME_SetActiveTheme(pt);
188 TRACE("Theme active: %s %s %s\n", debugstr_w(szCurrentTheme),
189 debugstr_w(szCurrentColor), debugstr_w(szCurrentSize));
190 MSSTYLES_CloseThemeFile(pt);
193 if(!bThemeActive) {
194 MSSTYLES_SetActiveTheme(NULL, FALSE);
195 TRACE("Theming not active\n");
199 /***********************************************************************/
201 static const WCHAR * const SysColorsNames[] =
203 L"Scrollbar", /* COLOR_SCROLLBAR */
204 L"Background", /* COLOR_BACKGROUND */
205 L"ActiveTitle", /* COLOR_ACTIVECAPTION */
206 L"InactiveTitle", /* COLOR_INACTIVECAPTION */
207 L"Menu", /* COLOR_MENU */
208 L"Window", /* COLOR_WINDOW */
209 L"WindowFrame", /* COLOR_WINDOWFRAME */
210 L"MenuText", /* COLOR_MENUTEXT */
211 L"WindowText", /* COLOR_WINDOWTEXT */
212 L"TitleText", /* COLOR_CAPTIONTEXT */
213 L"ActiveBorder", /* COLOR_ACTIVEBORDER */
214 L"InactiveBorder", /* COLOR_INACTIVEBORDER */
215 L"AppWorkSpace", /* COLOR_APPWORKSPACE */
216 L"Hilight", /* COLOR_HIGHLIGHT */
217 L"HilightText", /* COLOR_HIGHLIGHTTEXT */
218 L"ButtonFace", /* COLOR_BTNFACE */
219 L"ButtonShadow", /* COLOR_BTNSHADOW */
220 L"GrayText", /* COLOR_GRAYTEXT */
221 L"ButtonText", /* COLOR_BTNTEXT */
222 L"InactiveTitleText", /* COLOR_INACTIVECAPTIONTEXT */
223 L"ButtonHilight", /* COLOR_BTNHIGHLIGHT */
224 L"ButtonDkShadow", /* COLOR_3DDKSHADOW */
225 L"ButtonLight", /* COLOR_3DLIGHT */
226 L"InfoText", /* COLOR_INFOTEXT */
227 L"InfoWindow", /* COLOR_INFOBK */
228 L"ButtonAlternateFace", /* COLOR_ALTERNATEBTNFACE */
229 L"HotTrackingColor", /* COLOR_HOTLIGHT */
230 L"GradientActiveTitle", /* COLOR_GRADIENTACTIVECAPTION */
231 L"GradientInactiveTitle", /* COLOR_GRADIENTINACTIVECAPTION */
232 L"MenuHilight", /* COLOR_MENUHILIGHT */
233 L"MenuBar", /* COLOR_MENUBAR */
236 static const WCHAR strColorKey[] = L"Control Panel\\Colors";
238 #define NUM_SYS_COLORS (COLOR_MENUBAR+1)
240 struct system_metrics
242 COLORREF system_colors[NUM_SYS_COLORS];
243 NONCLIENTMETRICSW non_client_metrics;
244 LOGFONTW icon_title_font;
245 DWORD gradient_caption;
246 DWORD flat_menu;
249 static BOOL UXTHEME_GetSystemMetrics(struct system_metrics *metrics)
251 DPI_AWARENESS_CONTEXT old_context;
252 BOOL ret = FALSE;
253 int i;
255 for (i = 0; i < NUM_SYS_COLORS; ++i)
256 metrics->system_colors[i] = GetSysColor(i);
258 old_context = SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE);
260 memset(&metrics->non_client_metrics, 0, sizeof(metrics->non_client_metrics));
261 metrics->non_client_metrics.cbSize = sizeof(metrics->non_client_metrics);
262 if (!SystemParametersInfoW(SPI_GETNONCLIENTMETRICS, sizeof(metrics->non_client_metrics),
263 &metrics->non_client_metrics, 0))
264 goto done;
265 memset(&metrics->icon_title_font, 0, sizeof(metrics->icon_title_font));
266 if (!SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(metrics->icon_title_font),
267 &metrics->icon_title_font, 0))
268 goto done;
269 if (!SystemParametersInfoW(SPI_GETGRADIENTCAPTIONS, 0, &metrics->gradient_caption, 0))
270 goto done;
271 if (!SystemParametersInfoW(SPI_GETFLATMENU, 0, &metrics->flat_menu, 0))
272 goto done;
274 ret = TRUE;
275 done:
276 SetThreadDpiAwarenessContext(old_context);
277 return ret;
280 /* Read back old settings after a theme was deactivated */
281 static BOOL UXTHEME_GetUnthemedSystemMetrics(struct system_metrics *metrics)
283 HKEY theme_manager_key = NULL, color_key = NULL;
284 BOOL ret = FALSE;
285 WCHAR string[13];
286 int i, r, g, b;
287 DWORD size;
289 if (RegOpenKeyExW(HKEY_CURRENT_USER, szThemeManager, 0, KEY_QUERY_VALUE, &theme_manager_key))
290 goto done;
292 if (RegOpenKeyExW(theme_manager_key, strColorKey, 0, KEY_QUERY_VALUE, &color_key))
293 goto done;
295 for (i = 0; i < NUM_SYS_COLORS; ++i)
297 size = sizeof(string);
298 if (RegQueryValueExW(color_key, SysColorsNames[i], 0, NULL, (BYTE *)string, &size))
299 goto done;
301 if (swscanf(string, L"%d %d %d", &r, &g, &b) != 3)
302 goto done;
304 metrics->system_colors[i] = RGB(r, g, b);
307 size = sizeof(metrics->non_client_metrics);
308 if (RegQueryValueExW(theme_manager_key, L"NonClientMetrics", 0, NULL,
309 (BYTE *)&metrics->non_client_metrics, &size))
310 goto done;
311 size = sizeof(metrics->icon_title_font);
312 if (RegQueryValueExW(theme_manager_key, L"IconTitleFont", 0, NULL,
313 (BYTE *)&metrics->icon_title_font, &size))
314 goto done;
315 size = sizeof(metrics->gradient_caption);
316 if (RegQueryValueExW(theme_manager_key, L"GradientCaption", 0, NULL,
317 (BYTE *)&metrics->gradient_caption, &size))
318 goto done;
319 size = sizeof(metrics->flat_menu);
320 if (RegQueryValueExW(theme_manager_key, L"FlatMenu", 0, NULL, (BYTE *)&metrics->flat_menu,
321 &size))
322 goto done;
324 ret = TRUE;
325 done:
326 RegCloseKey(color_key);
327 RegCloseKey(theme_manager_key);
328 return ret;
331 static void UXTHEME_SaveUnthemedSystemMetrics(struct system_metrics *metrics)
333 HKEY theme_manager_key, color_key;
334 WCHAR string[13];
335 DWORD length;
336 int i;
338 if (!RegCreateKeyExW(HKEY_CURRENT_USER, szThemeManager, 0, 0, 0, KEY_ALL_ACCESS, 0,
339 &theme_manager_key, 0))
341 if (!RegCreateKeyExW(theme_manager_key, strColorKey, 0, 0, 0, KEY_ALL_ACCESS, 0, &color_key,
344 for (i = 0; i < NUM_SYS_COLORS; ++i)
346 length = swprintf(string, ARRAY_SIZE(string), L"%d %d %d",
347 GetRValue(metrics->system_colors[i]),
348 GetGValue(metrics->system_colors[i]),
349 GetBValue(metrics->system_colors[i]));
350 RegSetValueExW(color_key, SysColorsNames[i], 0, REG_SZ, (BYTE *)string,
351 (length + 1) * sizeof(WCHAR));
354 RegCloseKey(color_key);
357 RegSetValueExW(theme_manager_key, L"NonClientMetrics", 0, REG_BINARY,
358 (BYTE *)&metrics->non_client_metrics, sizeof(metrics->non_client_metrics));
359 RegSetValueExW(theme_manager_key, L"IconTitleFont", 0, REG_BINARY,
360 (BYTE *)&metrics->icon_title_font, sizeof(metrics->icon_title_font));
361 RegSetValueExW(theme_manager_key, L"GradientCaption", 0, REG_DWORD,
362 (BYTE *)&metrics->gradient_caption, sizeof(metrics->gradient_caption));
363 RegSetValueExW(theme_manager_key, L"FlatMenu", 0, REG_DWORD, (BYTE *)&metrics->flat_menu,
364 sizeof(metrics->flat_menu));
365 RegCloseKey(theme_manager_key);
369 /* Make system settings persistent, so they're in effect even w/o uxtheme
370 * loaded.
371 * For efficiency reasons, only the last SystemParametersInfoW sets
372 * SPIF_SENDWININICHANGE */
373 static void UXTHEME_SaveSystemMetrics(struct system_metrics *metrics, BOOL send_syscolor_change)
375 int i, length, index[NUM_SYS_COLORS];
376 DPI_AWARENESS_CONTEXT old_context;
377 WCHAR string[13];
378 HKEY hkey;
380 if (!RegCreateKeyExW(HKEY_CURRENT_USER, strColorKey, 0, 0, 0, KEY_ALL_ACCESS, 0, &hkey, 0))
382 for (i = 0; i < NUM_SYS_COLORS; ++i)
384 length = swprintf(string, ARRAY_SIZE(string), L"%d %d %d",
385 GetRValue(metrics->system_colors[i]),
386 GetGValue(metrics->system_colors[i]),
387 GetBValue(metrics->system_colors[i]));
388 RegSetValueExW(hkey, SysColorsNames[i], 0, REG_SZ, (BYTE *)string,
389 (length + 1) * sizeof(WCHAR));
391 RegCloseKey(hkey);
394 if (send_syscolor_change)
396 for (i = 0; i < NUM_SYS_COLORS; ++i)
397 index[i] = i;
399 SetSysColors(NUM_SYS_COLORS, index, metrics->system_colors);
402 old_context = SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE);
404 SystemParametersInfoW(SPI_SETNONCLIENTMETRICS, sizeof(metrics->non_client_metrics),
405 &metrics->non_client_metrics, SPIF_UPDATEINIFILE);
406 SystemParametersInfoW(SPI_SETICONTITLELOGFONT, sizeof(metrics->icon_title_font),
407 &metrics->icon_title_font, SPIF_UPDATEINIFILE);
408 SystemParametersInfoW(SPI_SETGRADIENTCAPTIONS, 0, (void *)(INT_PTR)metrics->gradient_caption,
409 SPIF_UPDATEINIFILE);
410 SystemParametersInfoW(SPI_SETFLATMENU, 0, (void *)(INT_PTR)metrics->flat_menu,
411 SPIF_UPDATEINIFILE | SPIF_SENDCHANGE);
413 SetThreadDpiAwarenessContext(old_context);
416 /***********************************************************************
417 * UXTHEME_SetActiveTheme
419 * Change the current active theme
421 HRESULT UXTHEME_SetActiveTheme(PTHEME_FILE tf)
423 BOOL ret, loaded_before = FALSE, same_theme = FALSE;
424 struct system_metrics metrics;
425 DWORD size;
426 HKEY hKey;
427 WCHAR tmp[2];
428 HRESULT hr;
430 if(tf) {
431 bThemeActive = TRUE;
432 same_theme = !lstrcmpW(szCurrentTheme, tf->szThemeFile)
433 && !lstrcmpW(szCurrentColor, tf->pszSelectedColor)
434 && !lstrcmpW(szCurrentSize, tf->pszSelectedSize);
435 lstrcpynW(szCurrentTheme, tf->szThemeFile, ARRAY_SIZE(szCurrentTheme));
436 lstrcpynW(szCurrentColor, tf->pszSelectedColor, ARRAY_SIZE(szCurrentColor));
437 lstrcpynW(szCurrentSize, tf->pszSelectedSize, ARRAY_SIZE(szCurrentSize));
439 ret = UXTHEME_GetSystemMetrics(&metrics);
441 /* Check if theming is already active */
442 if (!RegOpenKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey))
444 size = sizeof(tmp);
445 if (!RegQueryValueExW(hKey, L"LoadedBefore", NULL, NULL, (BYTE *)tmp, &size))
446 loaded_before = (tmp[0] != '0');
447 else
448 WARN("Failed to get LoadedBefore: %ld\n", GetLastError());
449 RegCloseKey(hKey);
451 if (loaded_before && same_theme)
452 return MSSTYLES_SetActiveTheme(tf, FALSE);
454 if (!loaded_before && ret)
455 UXTHEME_SaveUnthemedSystemMetrics(&metrics);
457 else {
458 bThemeActive = FALSE;
459 szCurrentTheme[0] = '\0';
460 szCurrentColor[0] = '\0';
461 szCurrentSize[0] = '\0';
464 TRACE("Writing theme config to registry\n");
465 if(!RegCreateKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
466 tmp[0] = bThemeActive?'1':'0';
467 tmp[1] = '\0';
468 RegSetValueExW(hKey, L"ThemeActive", 0, REG_SZ, (const BYTE*)tmp, sizeof(WCHAR)*2);
469 if(bThemeActive) {
470 RegSetValueExW(hKey, L"ColorName", 0, REG_SZ, (const BYTE*)szCurrentColor,
471 (lstrlenW(szCurrentColor)+1)*sizeof(WCHAR));
472 RegSetValueExW(hKey, L"SizeName", 0, REG_SZ, (const BYTE*)szCurrentSize,
473 (lstrlenW(szCurrentSize)+1)*sizeof(WCHAR));
474 RegSetValueExW(hKey, L"DllName", 0, REG_SZ, (const BYTE*)szCurrentTheme,
475 (lstrlenW(szCurrentTheme)+1)*sizeof(WCHAR));
476 RegSetValueExW(hKey, L"LoadedBefore", 0, REG_SZ, (const BYTE *)tmp, sizeof(WCHAR) * 2);
478 else {
479 RegDeleteValueW(hKey, L"ColorName");
480 RegDeleteValueW(hKey, L"SizeName");
481 RegDeleteValueW(hKey, L"DllName");
482 RegDeleteValueW(hKey, L"LoadedBefore");
484 RegCloseKey(hKey);
486 else
487 TRACE("Failed to open theme registry key\n");
489 hr = MSSTYLES_SetActiveTheme(tf, TRUE);
490 if (bThemeActive)
492 if (UXTHEME_GetSystemMetrics(&metrics))
493 UXTHEME_SaveSystemMetrics(&metrics, FALSE);
495 else
497 if (UXTHEME_GetUnthemedSystemMetrics(&metrics))
498 UXTHEME_SaveSystemMetrics(&metrics, TRUE);
500 return hr;
503 /***********************************************************************
504 * UXTHEME_InitSystem
506 void UXTHEME_InitSystem(HINSTANCE hInst)
508 atWindowTheme = GlobalAddAtomW(L"ux_theme");
509 atSubAppName = GlobalAddAtomW(L"ux_subapp");
510 atSubIdList = GlobalAddAtomW(L"ux_subidlst");
511 atDialogThemeEnabled = GlobalAddAtomW(L"ux_dialogtheme");
513 UXTHEME_LoadTheme();
514 ThemeHooksInstall();
517 void UXTHEME_UninitSystem(void)
519 ThemeHooksRemove();
520 MSSTYLES_SetActiveTheme(NULL, FALSE);
522 GlobalDeleteAtom(atWindowTheme);
523 GlobalDeleteAtom(atSubAppName);
524 GlobalDeleteAtom(atSubIdList);
525 GlobalDeleteAtom(atDialogThemeEnabled);
528 /***********************************************************************
529 * IsAppThemed (UXTHEME.@)
531 BOOL WINAPI IsAppThemed(void)
533 return IsThemeActive();
536 /***********************************************************************
537 * IsThemeActive (UXTHEME.@)
539 BOOL WINAPI IsThemeActive(void)
541 TRACE("\n");
542 SetLastError(ERROR_SUCCESS);
543 return bThemeActive;
546 /************************************************************
547 * IsCompositionActive (UXTHEME.@)
549 BOOL WINAPI IsCompositionActive(void)
551 FIXME(": stub\n");
553 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
555 return FALSE;
558 /***********************************************************************
559 * EnableTheming (UXTHEME.@)
561 * NOTES
562 * This is a global and persistent change
564 HRESULT WINAPI EnableTheming(BOOL fEnable)
566 HKEY hKey;
568 TRACE("(%d)\n", fEnable);
570 if (bThemeActive && !fEnable)
572 bThemeActive = fEnable;
573 if(!RegOpenKeyW(HKEY_CURRENT_USER, szThemeManager, &hKey)) {
574 RegSetValueExW(hKey, L"ThemeActive", 0, REG_SZ, (BYTE *)L"0", 2 * sizeof(WCHAR));
575 RegCloseKey(hKey);
577 UXTHEME_broadcast_msg (NULL, WM_THEMECHANGED);
579 return S_OK;
582 /***********************************************************************
583 * UXTHEME_SetWindowProperty
585 * I'm using atoms as there may be large numbers of duplicated strings
586 * and they do the work of keeping memory down as a cause of that quite nicely
588 static HRESULT UXTHEME_SetWindowProperty(HWND hwnd, ATOM aProp, LPCWSTR pszValue)
590 ATOM oldValue = (ATOM)(size_t)RemovePropW(hwnd, (LPCWSTR)MAKEINTATOM(aProp));
591 if(oldValue)
592 DeleteAtom(oldValue);
593 if(pszValue) {
594 ATOM atValue = AddAtomW(pszValue);
595 if(!atValue
596 || !SetPropW(hwnd, (LPCWSTR)MAKEINTATOM(aProp), (LPWSTR)MAKEINTATOM(atValue))) {
597 HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
598 if(atValue) DeleteAtom(atValue);
599 return hr;
602 return S_OK;
605 static LPWSTR UXTHEME_GetWindowProperty(HWND hwnd, ATOM aProp, LPWSTR pszBuffer, int dwLen)
607 ATOM atValue = (ATOM)(size_t)GetPropW(hwnd, (LPCWSTR)MAKEINTATOM(aProp));
608 if(atValue) {
609 if(GetAtomNameW(atValue, pszBuffer, dwLen))
610 return pszBuffer;
611 TRACE("property defined, but unable to get value\n");
613 return NULL;
616 static HTHEME open_theme_data(HWND hwnd, LPCWSTR pszClassList, DWORD flags, UINT dpi)
618 WCHAR szAppBuff[256];
619 WCHAR szClassBuff[256];
620 LPCWSTR pszAppName;
621 LPCWSTR pszUseClassList;
622 HTHEME hTheme = NULL;
623 TRACE("(%p,%s, %lx)\n", hwnd, debugstr_w(pszClassList), flags);
625 if(!pszClassList)
627 SetLastError(E_POINTER);
628 return NULL;
631 if(flags)
632 FIXME("unhandled flags: %lx\n", flags);
634 if(bThemeActive)
636 pszAppName = UXTHEME_GetWindowProperty(hwnd, atSubAppName, szAppBuff, ARRAY_SIZE(szAppBuff));
637 /* If SetWindowTheme was used on the window, that overrides the class list passed to this function */
638 pszUseClassList = UXTHEME_GetWindowProperty(hwnd, atSubIdList, szClassBuff, ARRAY_SIZE(szClassBuff));
639 if(!pszUseClassList)
640 pszUseClassList = pszClassList;
642 if (pszUseClassList)
643 hTheme = MSSTYLES_OpenThemeClass(pszAppName, pszUseClassList, dpi);
645 if(IsWindow(hwnd))
646 SetPropW(hwnd, (LPCWSTR)MAKEINTATOM(atWindowTheme), hTheme);
647 TRACE(" = %p\n", hTheme);
649 SetLastError(hTheme ? ERROR_SUCCESS : E_PROP_ID_UNSUPPORTED);
650 return hTheme;
653 /***********************************************************************
654 * OpenThemeDataEx (UXTHEME.61)
656 HTHEME WINAPI OpenThemeDataEx(HWND hwnd, LPCWSTR pszClassList, DWORD flags)
658 UINT dpi;
660 dpi = GetDpiForWindow(hwnd);
661 if (!dpi)
662 dpi = GetDpiForSystem();
664 return open_theme_data(hwnd, pszClassList, flags, dpi);
667 /***********************************************************************
668 * OpenThemeDataForDpi (UXTHEME.@)
670 HTHEME WINAPI OpenThemeDataForDpi(HWND hwnd, LPCWSTR class_list, UINT dpi)
672 return open_theme_data(hwnd, class_list, 0, dpi);
675 /***********************************************************************
676 * OpenThemeData (UXTHEME.@)
678 HTHEME WINAPI OpenThemeData(HWND hwnd, LPCWSTR classlist)
680 return OpenThemeDataEx(hwnd, classlist, 0);
683 /***********************************************************************
684 * GetWindowTheme (UXTHEME.@)
686 * Retrieve the last theme opened for a window.
688 * PARAMS
689 * hwnd [I] window to retrieve the theme for
691 * RETURNS
692 * The most recent theme.
694 HTHEME WINAPI GetWindowTheme(HWND hwnd)
696 TRACE("(%p)\n", hwnd);
698 if (!hwnd)
700 SetLastError(E_HANDLE);
701 return NULL;
704 return GetPropW(hwnd, (LPCWSTR)MAKEINTATOM(atWindowTheme));
707 /***********************************************************************
708 * SetWindowTheme (UXTHEME.@)
710 * Persistent through the life of the window, even after themes change
712 HRESULT WINAPI SetWindowTheme(HWND hwnd, LPCWSTR pszSubAppName,
713 LPCWSTR pszSubIdList)
715 HRESULT hr;
716 TRACE("(%p,%s,%s)\n", hwnd, debugstr_w(pszSubAppName),
717 debugstr_w(pszSubIdList));
719 if (!hwnd)
720 return E_HANDLE;
722 hr = UXTHEME_SetWindowProperty(hwnd, atSubAppName, pszSubAppName);
723 if(SUCCEEDED(hr))
724 hr = UXTHEME_SetWindowProperty(hwnd, atSubIdList, pszSubIdList);
725 if(SUCCEEDED(hr))
726 SendMessageW(hwnd, WM_THEMECHANGED, 0, 0);
727 return hr;
730 /***********************************************************************
731 * SetWindowThemeAttribute (UXTHEME.@)
733 HRESULT WINAPI SetWindowThemeAttribute(HWND hwnd, enum WINDOWTHEMEATTRIBUTETYPE type,
734 PVOID attribute, DWORD size)
736 FIXME("(%p,%d,%p,%ld): stub\n", hwnd, type, attribute, size);
737 return E_NOTIMPL;
740 /***********************************************************************
741 * GetCurrentThemeName (UXTHEME.@)
743 HRESULT WINAPI GetCurrentThemeName(LPWSTR pszThemeFileName, int dwMaxNameChars,
744 LPWSTR pszColorBuff, int cchMaxColorChars,
745 LPWSTR pszSizeBuff, int cchMaxSizeChars)
747 if(!bThemeActive)
748 return E_PROP_ID_UNSUPPORTED;
749 if(pszThemeFileName) lstrcpynW(pszThemeFileName, szCurrentTheme, dwMaxNameChars);
750 if(pszColorBuff) lstrcpynW(pszColorBuff, szCurrentColor, cchMaxColorChars);
751 if(pszSizeBuff) lstrcpynW(pszSizeBuff, szCurrentSize, cchMaxSizeChars);
752 return S_OK;
755 /***********************************************************************
756 * GetThemeAppProperties (UXTHEME.@)
758 DWORD WINAPI GetThemeAppProperties(void)
760 return dwThemeAppProperties;
763 /***********************************************************************
764 * SetThemeAppProperties (UXTHEME.@)
766 void WINAPI SetThemeAppProperties(DWORD dwFlags)
768 TRACE("(0x%08lx)\n", dwFlags);
769 dwThemeAppProperties = dwFlags;
772 /***********************************************************************
773 * CloseThemeData (UXTHEME.@)
775 HRESULT WINAPI CloseThemeData(HTHEME hTheme)
777 TRACE("(%p)\n", hTheme);
778 if(!hTheme || hTheme == INVALID_HANDLE_VALUE)
779 return E_HANDLE;
780 return MSSTYLES_CloseThemeClass(hTheme);
783 /***********************************************************************
784 * HitTestThemeBackground (UXTHEME.@)
786 HRESULT WINAPI HitTestThemeBackground(HTHEME hTheme, HDC hdc, int iPartId,
787 int iStateId, DWORD dwOptions,
788 const RECT *pRect, HRGN hrgn,
789 POINT ptTest, WORD *pwHitTestCode)
791 FIXME("%d %d 0x%08lx: stub\n", iPartId, iStateId, dwOptions);
792 if(!hTheme)
793 return E_HANDLE;
794 return E_NOTIMPL;
797 /***********************************************************************
798 * IsThemePartDefined (UXTHEME.@)
800 BOOL WINAPI IsThemePartDefined(HTHEME hTheme, int iPartId, int iStateId)
802 TRACE("(%p,%d,%d)\n", hTheme, iPartId, iStateId);
803 if(!hTheme) {
804 SetLastError(E_HANDLE);
805 return FALSE;
808 SetLastError(NO_ERROR);
809 return !iStateId && MSSTYLES_FindPart(hTheme, iPartId);
812 /***********************************************************************
813 * GetThemeDocumentationProperty (UXTHEME.@)
815 * Try and retrieve the documentation property from string resources
816 * if that fails, get it from the [documentation] section of themes.ini
818 HRESULT WINAPI GetThemeDocumentationProperty(LPCWSTR pszThemeName,
819 LPCWSTR pszPropertyName,
820 LPWSTR pszValueBuff,
821 int cchMaxValChars)
823 static const WORD wDocToRes[] = {
824 TMT_DISPLAYNAME,5000,
825 TMT_TOOLTIP,5001,
826 TMT_COMPANY,5002,
827 TMT_AUTHOR,5003,
828 TMT_COPYRIGHT,5004,
829 TMT_URL,5005,
830 TMT_VERSION,5006,
831 TMT_DESCRIPTION,5007
834 PTHEME_FILE pt;
835 HRESULT hr;
836 unsigned int i;
837 int iDocId;
838 TRACE("(%s,%s,%p,%d)\n", debugstr_w(pszThemeName), debugstr_w(pszPropertyName),
839 pszValueBuff, cchMaxValChars);
841 hr = MSSTYLES_OpenThemeFile(pszThemeName, NULL, NULL, &pt);
842 if(FAILED(hr)) return hr;
844 /* Try to load from string resources */
845 hr = E_PROP_ID_UNSUPPORTED;
846 if(MSSTYLES_LookupProperty(pszPropertyName, NULL, &iDocId)) {
847 for(i=0; i<ARRAY_SIZE(wDocToRes); i+=2) {
848 if(wDocToRes[i] == iDocId) {
849 if(LoadStringW(pt->hTheme, wDocToRes[i+1], pszValueBuff, cchMaxValChars)) {
850 hr = S_OK;
851 break;
856 /* If loading from string resource failed, try getting it from the theme.ini */
857 if(FAILED(hr)) {
858 PUXINI_FILE uf = MSSTYLES_GetThemeIni(pt);
859 if(UXINI_FindSection(uf, L"documentation")) {
860 LPCWSTR lpValue;
861 DWORD dwLen;
862 if(UXINI_FindValue(uf, pszPropertyName, &lpValue, &dwLen)) {
863 lstrcpynW(pszValueBuff, lpValue, min(dwLen+1,cchMaxValChars));
864 hr = S_OK;
867 UXINI_CloseINI(uf);
870 MSSTYLES_CloseThemeFile(pt);
871 return hr;
874 /**********************************************************************
875 * Undocumented functions
878 /**********************************************************************
879 * QueryThemeServices (UXTHEME.1)
881 * RETURNS
882 * some kind of status flag
884 DWORD WINAPI QueryThemeServices(void)
886 FIXME("stub\n");
887 return 3; /* This is what is returned under XP in most cases */
891 /**********************************************************************
892 * OpenThemeFile (UXTHEME.2)
894 * Opens a theme file, which can be used to change the current theme, etc
896 * PARAMS
897 * pszThemeFileName Path to a msstyles theme file
898 * pszColorName Color defined in the theme, eg. NormalColor
899 * pszSizeName Size defined in the theme, eg. NormalSize
900 * hThemeFile Handle to theme file
902 * RETURNS
903 * Success: S_OK
904 * Failure: HRESULT error-code
906 HRESULT WINAPI OpenThemeFile(LPCWSTR pszThemeFileName, LPCWSTR pszColorName,
907 LPCWSTR pszSizeName, HTHEMEFILE *hThemeFile,
908 DWORD unknown)
910 TRACE("(%s,%s,%s,%p,%ld)\n", debugstr_w(pszThemeFileName),
911 debugstr_w(pszColorName), debugstr_w(pszSizeName),
912 hThemeFile, unknown);
913 return MSSTYLES_OpenThemeFile(pszThemeFileName, pszColorName, pszSizeName, (PTHEME_FILE*)hThemeFile);
916 /**********************************************************************
917 * CloseThemeFile (UXTHEME.3)
919 * Releases theme file handle returned by OpenThemeFile
921 * PARAMS
922 * hThemeFile Handle to theme file
924 * RETURNS
925 * Success: S_OK
926 * Failure: HRESULT error-code
928 HRESULT WINAPI CloseThemeFile(HTHEMEFILE hThemeFile)
930 TRACE("(%p)\n", hThemeFile);
931 MSSTYLES_CloseThemeFile(hThemeFile);
932 return S_OK;
935 /**********************************************************************
936 * ApplyTheme (UXTHEME.4)
938 * Set a theme file to be the currently active theme
940 * PARAMS
941 * hThemeFile Handle to theme file
942 * unknown See notes
943 * hWnd Window requesting the theme change
945 * RETURNS
946 * Success: S_OK
947 * Failure: HRESULT error-code
949 * NOTES
950 * I'm not sure what the second parameter is (the datatype is likely wrong), other then this:
951 * Under XP if I pass
952 * char b[] = "";
953 * the theme is applied with the screen redrawing really badly (flickers)
954 * char b[] = "\0"; where \0 can be one or more of any character, makes no difference
955 * the theme is applied smoothly (screen does not flicker)
956 * char *b = "\0" or NULL; where \0 can be zero or more of any character, makes no difference
957 * the function fails returning invalid parameter... very strange
959 HRESULT WINAPI ApplyTheme(HTHEMEFILE hThemeFile, char *unknown, HWND hWnd)
961 HRESULT hr;
962 TRACE("(%p,%s,%p)\n", hThemeFile, unknown, hWnd);
963 hr = UXTHEME_SetActiveTheme(hThemeFile);
964 UXTHEME_broadcast_msg (NULL, WM_THEMECHANGED);
965 return hr;
968 /**********************************************************************
969 * GetThemeDefaults (UXTHEME.7)
971 * Get the default color & size for a theme
973 * PARAMS
974 * pszThemeFileName Path to a msstyles theme file
975 * pszColorName Buffer to receive the default color name
976 * dwColorNameLen Length, in characters, of color name buffer
977 * pszSizeName Buffer to receive the default size name
978 * dwSizeNameLen Length, in characters, of size name buffer
980 * RETURNS
981 * Success: S_OK
982 * Failure: HRESULT error-code
984 HRESULT WINAPI GetThemeDefaults(LPCWSTR pszThemeFileName, LPWSTR pszColorName,
985 DWORD dwColorNameLen, LPWSTR pszSizeName,
986 DWORD dwSizeNameLen)
988 PTHEME_FILE pt;
989 HRESULT hr;
990 TRACE("(%s,%p,%ld,%p,%ld)\n", debugstr_w(pszThemeFileName),
991 pszColorName, dwColorNameLen,
992 pszSizeName, dwSizeNameLen);
994 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt);
995 if(FAILED(hr)) return hr;
997 lstrcpynW(pszColorName, pt->pszSelectedColor, dwColorNameLen);
998 lstrcpynW(pszSizeName, pt->pszSelectedSize, dwSizeNameLen);
1000 MSSTYLES_CloseThemeFile(pt);
1001 return S_OK;
1004 /**********************************************************************
1005 * EnumThemes (UXTHEME.8)
1007 * Enumerate available themes, calls specified EnumThemeProc for each
1008 * theme found. Passes lpData through to callback function.
1010 * PARAMS
1011 * pszThemePath Path containing themes
1012 * callback Called for each theme found in path
1013 * lpData Passed through to callback
1015 * RETURNS
1016 * Success: S_OK
1017 * Failure: HRESULT error-code
1019 HRESULT WINAPI EnumThemes(LPCWSTR pszThemePath, EnumThemeProc callback,
1020 LPVOID lpData)
1022 WCHAR szDir[MAX_PATH];
1023 WCHAR szPath[MAX_PATH];
1024 WCHAR szName[60];
1025 WCHAR szTip[60];
1026 HANDLE hFind;
1027 WIN32_FIND_DATAW wfd;
1028 HRESULT hr;
1029 size_t pathLen;
1031 TRACE("(%s,%p,%p)\n", debugstr_w(pszThemePath), callback, lpData);
1033 if(!pszThemePath || !callback)
1034 return E_POINTER;
1036 lstrcpyW(szDir, pszThemePath);
1037 pathLen = lstrlenW (szDir);
1038 if ((pathLen > 0) && (pathLen < MAX_PATH-1) && (szDir[pathLen - 1] != '\\'))
1040 szDir[pathLen] = '\\';
1041 szDir[pathLen+1] = 0;
1044 lstrcpyW(szPath, szDir);
1045 lstrcatW(szPath, L"*.*");
1046 TRACE("searching %s\n", debugstr_w(szPath));
1048 hFind = FindFirstFileW(szPath, &wfd);
1049 if(hFind != INVALID_HANDLE_VALUE) {
1050 do {
1051 if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY
1052 && !(wfd.cFileName[0] == '.' && ((wfd.cFileName[1] == '.' && wfd.cFileName[2] == 0) || wfd.cFileName[1] == 0))) {
1053 wsprintfW(szPath, L"%s%s\\%s.msstyles", szDir, wfd.cFileName, wfd.cFileName);
1055 hr = GetThemeDocumentationProperty(szPath, L"displayname", szName, ARRAY_SIZE(szName));
1056 if(SUCCEEDED(hr))
1057 hr = GetThemeDocumentationProperty(szPath, L"tooltip", szTip, ARRAY_SIZE(szTip));
1058 if(SUCCEEDED(hr)) {
1059 TRACE("callback(%s,%s,%s,%p)\n", debugstr_w(szPath), debugstr_w(szName), debugstr_w(szTip), lpData);
1060 if(!callback(NULL, szPath, szName, szTip, NULL, lpData)) {
1061 TRACE("callback ended enum\n");
1062 break;
1066 } while(FindNextFileW(hFind, &wfd));
1067 FindClose(hFind);
1069 return S_OK;
1073 /**********************************************************************
1074 * EnumThemeColors (UXTHEME.9)
1076 * Enumerate theme colors available with a particular size
1078 * PARAMS
1079 * pszThemeFileName Path to a msstyles theme file
1080 * pszSizeName Theme size to enumerate available colors
1081 * If NULL the default theme size is used
1082 * dwColorNum Color index to retrieve, increment from 0
1083 * pszColorNames Output color names
1085 * RETURNS
1086 * S_OK on success
1087 * E_PROP_ID_UNSUPPORTED when dwColorName does not refer to a color
1088 * or when pszSizeName does not refer to a valid size
1090 * NOTES
1091 * XP fails with E_POINTER when pszColorNames points to a buffer smaller than
1092 * sizeof(THEMENAMES).
1094 * Not very efficient that I'm opening & validating the theme every call, but
1095 * this is undocumented and almost never called..
1096 * (and this is how windows works too)
1098 HRESULT WINAPI EnumThemeColors(LPWSTR pszThemeFileName, LPWSTR pszSizeName,
1099 DWORD dwColorNum, PTHEMENAMES pszColorNames)
1101 PTHEME_FILE pt;
1102 HRESULT hr;
1103 LPWSTR tmp;
1104 UINT resourceId = dwColorNum + 1000;
1105 TRACE("(%s,%s,%ld)\n", debugstr_w(pszThemeFileName),
1106 debugstr_w(pszSizeName), dwColorNum);
1108 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, pszSizeName, &pt);
1109 if(FAILED(hr)) return hr;
1111 tmp = pt->pszAvailColors;
1112 while(dwColorNum && *tmp) {
1113 dwColorNum--;
1114 tmp += lstrlenW(tmp)+1;
1116 if(!dwColorNum && *tmp) {
1117 TRACE("%s\n", debugstr_w(tmp));
1118 lstrcpyW(pszColorNames->szName, tmp);
1119 LoadStringW(pt->hTheme, resourceId, pszColorNames->szDisplayName,
1120 ARRAY_SIZE(pszColorNames->szDisplayName));
1121 LoadStringW(pt->hTheme, resourceId+1000, pszColorNames->szTooltip,
1122 ARRAY_SIZE(pszColorNames->szTooltip));
1124 else
1125 hr = E_PROP_ID_UNSUPPORTED;
1127 MSSTYLES_CloseThemeFile(pt);
1128 return hr;
1131 /**********************************************************************
1132 * EnumThemeSizes (UXTHEME.10)
1134 * Enumerate theme colors available with a particular size
1136 * PARAMS
1137 * pszThemeFileName Path to a msstyles theme file
1138 * pszColorName Theme color to enumerate available sizes
1139 * If NULL the default theme color is used
1140 * dwSizeNum Size index to retrieve, increment from 0
1141 * pszSizeNames Output size names
1143 * RETURNS
1144 * S_OK on success
1145 * E_PROP_ID_UNSUPPORTED when dwSizeName does not refer to a size
1146 * or when pszColorName does not refer to a valid color
1148 * NOTES
1149 * XP fails with E_POINTER when pszSizeNames points to a buffer smaller than
1150 * sizeof(THEMENAMES).
1152 * Not very efficient that I'm opening & validating the theme every call, but
1153 * this is undocumented and almost never called..
1154 * (and this is how windows works too)
1156 HRESULT WINAPI EnumThemeSizes(LPWSTR pszThemeFileName, LPWSTR pszColorName,
1157 DWORD dwSizeNum, PTHEMENAMES pszSizeNames)
1159 PTHEME_FILE pt;
1160 HRESULT hr;
1161 LPWSTR tmp;
1162 UINT resourceId = dwSizeNum + 3000;
1163 TRACE("(%s,%s,%ld)\n", debugstr_w(pszThemeFileName),
1164 debugstr_w(pszColorName), dwSizeNum);
1166 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, pszColorName, NULL, &pt);
1167 if(FAILED(hr)) return hr;
1169 tmp = pt->pszAvailSizes;
1170 while(dwSizeNum && *tmp) {
1171 dwSizeNum--;
1172 tmp += lstrlenW(tmp)+1;
1174 if(!dwSizeNum && *tmp) {
1175 TRACE("%s\n", debugstr_w(tmp));
1176 lstrcpyW(pszSizeNames->szName, tmp);
1177 LoadStringW(pt->hTheme, resourceId, pszSizeNames->szDisplayName,
1178 ARRAY_SIZE(pszSizeNames->szDisplayName));
1179 LoadStringW(pt->hTheme, resourceId+1000, pszSizeNames->szTooltip,
1180 ARRAY_SIZE(pszSizeNames->szTooltip));
1182 else
1183 hr = E_PROP_ID_UNSUPPORTED;
1185 MSSTYLES_CloseThemeFile(pt);
1186 return hr;
1189 /**********************************************************************
1190 * ParseThemeIniFile (UXTHEME.11)
1192 * Enumerate data in a theme INI file.
1194 * PARAMS
1195 * pszIniFileName Path to a theme ini file
1196 * pszUnknown Cannot be NULL, L"" is valid
1197 * callback Called for each found entry
1198 * lpData Passed through to callback
1200 * RETURNS
1201 * S_OK on success
1202 * 0x800706488 (Unknown property) when enumeration is canceled from callback
1204 * NOTES
1205 * When pszUnknown is NULL the callback is never called, the value does not seem to serve
1206 * any other purpose
1208 HRESULT WINAPI ParseThemeIniFile(LPCWSTR pszIniFileName, LPWSTR pszUnknown,
1209 ParseThemeIniFileProc callback, LPVOID lpData)
1211 FIXME("%s %s: stub\n", debugstr_w(pszIniFileName), debugstr_w(pszUnknown));
1212 return E_NOTIMPL;
1215 /**********************************************************************
1216 * CheckThemeSignature (UXTHEME.29)
1218 * Validates the signature of a theme file
1220 * PARAMS
1221 * pszIniFileName Path to a theme file
1223 * RETURNS
1224 * Success: S_OK
1225 * Failure: HRESULT error-code
1227 HRESULT WINAPI CheckThemeSignature(LPCWSTR pszThemeFileName)
1229 PTHEME_FILE pt;
1230 HRESULT hr;
1231 TRACE("(%s)\n", debugstr_w(pszThemeFileName));
1232 hr = MSSTYLES_OpenThemeFile(pszThemeFileName, NULL, NULL, &pt);
1233 if(FAILED(hr))
1234 return hr;
1235 MSSTYLES_CloseThemeFile(pt);
1236 return S_OK;
1239 BOOL WINAPI ThemeHooksInstall(void)
1241 struct user_api_hook hooks;
1243 hooks.pDefDlgProc = UXTHEME_DefDlgProc;
1244 hooks.pNonClientButtonDraw = UXTHEME_NonClientButtonDraw;
1245 hooks.pScrollBarDraw = UXTHEME_ScrollBarDraw;
1246 hooks.pScrollBarWndProc = UXTHEME_ScrollbarWndProc;
1247 return RegisterUserApiHook(&hooks, &user_api);
1250 BOOL WINAPI ThemeHooksRemove(void)
1252 UnregisterUserApiHook();
1253 return TRUE;
1256 /**********************************************************************
1257 * RefreshImmersiveColorPolicyState (UXTHEME.104)
1260 void WINAPI RefreshImmersiveColorPolicyState(void)
1262 FIXME("stub\n");
1265 /**********************************************************************
1266 * ShouldSystemUseDarkMode (UXTHEME.138)
1268 * RETURNS
1269 * Whether or not the system should use dark mode.
1271 BOOL WINAPI ShouldSystemUseDarkMode(void)
1273 DWORD light_theme = TRUE, light_theme_size = sizeof(light_theme);
1275 RegGetValueW(HKEY_CURRENT_USER,
1276 L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
1277 L"SystemUsesLightTheme", RRF_RT_REG_DWORD, NULL, &light_theme, &light_theme_size);
1279 return !light_theme;
1282 /**********************************************************************
1283 * ShouldAppsUseDarkMode (UXTHEME.132)
1285 * RETURNS
1286 * Whether or not apps should use dark mode.
1288 BOOL WINAPI ShouldAppsUseDarkMode(void)
1290 DWORD light_theme = TRUE, light_theme_size = sizeof(light_theme);
1292 RegGetValueW(HKEY_CURRENT_USER,
1293 L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
1294 L"AppsUseLightTheme", RRF_RT_REG_DWORD, NULL, &light_theme, &light_theme_size);
1296 return !light_theme;
1299 /**********************************************************************
1300 * AllowDarkModeForWindow (UXTHEME.133)
1303 BOOL WINAPI AllowDarkModeForWindow(HWND hwnd, BOOL allow)
1305 FIXME("%p %d: stub\n", hwnd, allow);
1306 return FALSE;
1309 /**********************************************************************
1310 * SetPreferredAppMode (UXTHEME.135)
1313 int WINAPI SetPreferredAppMode(int app_mode)
1315 FIXME("%d: stub\n", app_mode);
1316 return 0;