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
33 #include "uxthemedll.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);
68 /* Broadcast a message to *all* windows, including children */
69 static BOOL CALLBACK
UXTHEME_broadcast_msg (HWND hWnd
, LPARAM msg
)
73 EnumWindows (UXTHEME_broadcast_msg
, msg
);
77 PostMessageW(hWnd
, msg
, 0, 0);
78 EnumChildWindows (hWnd
, UXTHEME_broadcast_msg_enumchild
, msg
);
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
,
88 DWORD dwRet
, dwType
, dwUnExpDataLen
= MAX_PATH
* sizeof(WCHAR
), dwExpDataLen
;
90 TRACE("(hkey=%p,%s,%p)\n", hKey
, debugstr_w(lpszValue
),
93 dwRet
= RegQueryValueExW(hKey
, lpszValue
, 0, &dwType
, pvData
, &dwUnExpDataLen
);
94 if (dwRet
!=ERROR_SUCCESS
&& dwRet
!=ERROR_MORE_DATA
)
97 if (dwType
== REG_EXPAND_SZ
)
101 /* Expand type REG_EXPAND_SZ into REG_SZ */
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
);
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
);
133 /***********************************************************************
136 * Set the current active theme from the registry
138 static void UXTHEME_LoadTheme(void)
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');
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';
168 TRACE("Failed to open theme registry key\n");
171 /* Make sure the theme requested is actually valid */
172 hr
= MSSTYLES_OpenThemeFile(szCurrentTheme
,
173 szCurrentColor
[0]?szCurrentColor
:NULL
,
174 szCurrentSize
[0]?szCurrentSize
:NULL
,
177 bThemeActive
= FALSE
;
178 szCurrentTheme
[0] = '\0';
179 szCurrentColor
[0] = '\0';
180 szCurrentSize
[0] = '\0';
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
);
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
;
249 static BOOL
UXTHEME_GetSystemMetrics(struct system_metrics
*metrics
)
251 DPI_AWARENESS_CONTEXT old_context
;
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))
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))
269 if (!SystemParametersInfoW(SPI_GETGRADIENTCAPTIONS
, 0, &metrics
->gradient_caption
, 0))
271 if (!SystemParametersInfoW(SPI_GETFLATMENU
, 0, &metrics
->flat_menu
, 0))
276 SetThreadDpiAwarenessContext(old_context
);
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
;
289 if (RegOpenKeyExW(HKEY_CURRENT_USER
, szThemeManager
, 0, KEY_QUERY_VALUE
, &theme_manager_key
))
292 if (RegOpenKeyExW(theme_manager_key
, strColorKey
, 0, KEY_QUERY_VALUE
, &color_key
))
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
))
301 if (swscanf(string
, L
"%d %d %d", &r
, &g
, &b
) != 3)
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
))
311 size
= sizeof(metrics
->icon_title_font
);
312 if (RegQueryValueExW(theme_manager_key
, L
"IconTitleFont", 0, NULL
,
313 (BYTE
*)&metrics
->icon_title_font
, &size
))
315 size
= sizeof(metrics
->gradient_caption
);
316 if (RegQueryValueExW(theme_manager_key
, L
"GradientCaption", 0, NULL
,
317 (BYTE
*)&metrics
->gradient_caption
, &size
))
319 size
= sizeof(metrics
->flat_menu
);
320 if (RegQueryValueExW(theme_manager_key
, L
"FlatMenu", 0, NULL
, (BYTE
*)&metrics
->flat_menu
,
326 RegCloseKey(color_key
);
327 RegCloseKey(theme_manager_key
);
331 static void UXTHEME_SaveUnthemedSystemMetrics(struct system_metrics
*metrics
)
333 HKEY theme_manager_key
, color_key
;
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
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
;
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
));
394 if (send_syscolor_change
)
396 for (i
= 0; i
< NUM_SYS_COLORS
; ++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
,
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
;
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
))
445 if (!RegQueryValueExW(hKey
, L
"LoadedBefore", NULL
, NULL
, (BYTE
*)tmp
, &size
))
446 loaded_before
= (tmp
[0] != '0');
448 WARN("Failed to get LoadedBefore: %ld\n", GetLastError());
451 if (loaded_before
&& same_theme
)
452 return MSSTYLES_SetActiveTheme(tf
, FALSE
);
454 if (!loaded_before
&& ret
)
455 UXTHEME_SaveUnthemedSystemMetrics(&metrics
);
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';
468 RegSetValueExW(hKey
, L
"ThemeActive", 0, REG_SZ
, (const BYTE
*)tmp
, sizeof(WCHAR
)*2);
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);
479 RegDeleteValueW(hKey
, L
"ColorName");
480 RegDeleteValueW(hKey
, L
"SizeName");
481 RegDeleteValueW(hKey
, L
"DllName");
482 RegDeleteValueW(hKey
, L
"LoadedBefore");
487 TRACE("Failed to open theme registry key\n");
489 hr
= MSSTYLES_SetActiveTheme(tf
, TRUE
);
492 if (UXTHEME_GetSystemMetrics(&metrics
))
493 UXTHEME_SaveSystemMetrics(&metrics
, FALSE
);
497 if (UXTHEME_GetUnthemedSystemMetrics(&metrics
))
498 UXTHEME_SaveSystemMetrics(&metrics
, TRUE
);
503 /***********************************************************************
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");
517 void UXTHEME_UninitSystem(void)
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)
542 SetLastError(ERROR_SUCCESS
);
546 /************************************************************
547 * IsCompositionActive (UXTHEME.@)
549 BOOL WINAPI
IsCompositionActive(void)
553 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
558 /***********************************************************************
559 * EnableTheming (UXTHEME.@)
562 * This is a global and persistent change
564 HRESULT WINAPI
EnableTheming(BOOL fEnable
)
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
));
577 UXTHEME_broadcast_msg (NULL
, WM_THEMECHANGED
);
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
));
592 DeleteAtom(oldValue
);
594 ATOM atValue
= AddAtomW(pszValue
);
596 || !SetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(aProp
), (LPWSTR
)MAKEINTATOM(atValue
))) {
597 HRESULT hr
= HRESULT_FROM_WIN32(GetLastError());
598 if(atValue
) DeleteAtom(atValue
);
605 static LPWSTR
UXTHEME_GetWindowProperty(HWND hwnd
, ATOM aProp
, LPWSTR pszBuffer
, int dwLen
)
607 ATOM atValue
= (ATOM
)(size_t)GetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(aProp
));
609 if(GetAtomNameW(atValue
, pszBuffer
, dwLen
))
611 TRACE("property defined, but unable to get value\n");
616 static HTHEME
open_theme_data(HWND hwnd
, LPCWSTR pszClassList
, DWORD flags
, UINT dpi
)
618 WCHAR szAppBuff
[256];
619 WCHAR szClassBuff
[256];
621 LPCWSTR pszUseClassList
;
622 HTHEME hTheme
= NULL
;
623 TRACE("(%p,%s, %lx)\n", hwnd
, debugstr_w(pszClassList
), flags
);
627 SetLastError(E_POINTER
);
632 FIXME("unhandled flags: %lx\n", flags
);
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
));
640 pszUseClassList
= pszClassList
;
643 hTheme
= MSSTYLES_OpenThemeClass(pszAppName
, pszUseClassList
, dpi
);
646 SetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(atWindowTheme
), hTheme
);
647 TRACE(" = %p\n", hTheme
);
649 SetLastError(hTheme
? ERROR_SUCCESS
: E_PROP_ID_UNSUPPORTED
);
653 /***********************************************************************
654 * OpenThemeDataEx (UXTHEME.61)
656 HTHEME WINAPI
OpenThemeDataEx(HWND hwnd
, LPCWSTR pszClassList
, DWORD flags
)
660 dpi
= GetDpiForWindow(hwnd
);
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.
689 * hwnd [I] window to retrieve the theme for
692 * The most recent theme.
694 HTHEME WINAPI
GetWindowTheme(HWND hwnd
)
696 TRACE("(%p)\n", hwnd
);
700 SetLastError(E_HANDLE
);
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
)
716 TRACE("(%p,%s,%s)\n", hwnd
, debugstr_w(pszSubAppName
),
717 debugstr_w(pszSubIdList
));
722 hr
= UXTHEME_SetWindowProperty(hwnd
, atSubAppName
, pszSubAppName
);
724 hr
= UXTHEME_SetWindowProperty(hwnd
, atSubIdList
, pszSubIdList
);
726 SendMessageW(hwnd
, WM_THEMECHANGED
, 0, 0);
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
);
740 /***********************************************************************
741 * GetCurrentThemeName (UXTHEME.@)
743 HRESULT WINAPI
GetCurrentThemeName(LPWSTR pszThemeFileName
, int dwMaxNameChars
,
744 LPWSTR pszColorBuff
, int cchMaxColorChars
,
745 LPWSTR pszSizeBuff
, int cchMaxSizeChars
)
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
);
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
)
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
);
797 /***********************************************************************
798 * IsThemePartDefined (UXTHEME.@)
800 BOOL WINAPI
IsThemePartDefined(HTHEME hTheme
, int iPartId
, int iStateId
)
802 TRACE("(%p,%d,%d)\n", hTheme
, iPartId
, iStateId
);
804 SetLastError(E_HANDLE
);
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
,
823 static const WORD wDocToRes
[] = {
824 TMT_DISPLAYNAME
,5000,
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
)) {
856 /* If loading from string resource failed, try getting it from the theme.ini */
858 PUXINI_FILE uf
= MSSTYLES_GetThemeIni(pt
);
859 if(UXINI_FindSection(uf
, L
"documentation")) {
862 if(UXINI_FindValue(uf
, pszPropertyName
, &lpValue
, &dwLen
)) {
863 lstrcpynW(pszValueBuff
, lpValue
, min(dwLen
+1,cchMaxValChars
));
870 MSSTYLES_CloseThemeFile(pt
);
874 /**********************************************************************
875 * Undocumented functions
878 /**********************************************************************
879 * QueryThemeServices (UXTHEME.1)
882 * some kind of status flag
884 DWORD WINAPI
QueryThemeServices(void)
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
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
904 * Failure: HRESULT error-code
906 HRESULT WINAPI
OpenThemeFile(LPCWSTR pszThemeFileName
, LPCWSTR pszColorName
,
907 LPCWSTR pszSizeName
, HTHEMEFILE
*hThemeFile
,
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
922 * hThemeFile Handle to theme file
926 * Failure: HRESULT error-code
928 HRESULT WINAPI
CloseThemeFile(HTHEMEFILE hThemeFile
)
930 TRACE("(%p)\n", hThemeFile
);
931 MSSTYLES_CloseThemeFile(hThemeFile
);
935 /**********************************************************************
936 * ApplyTheme (UXTHEME.4)
938 * Set a theme file to be the currently active theme
941 * hThemeFile Handle to theme file
943 * hWnd Window requesting the theme change
947 * Failure: HRESULT error-code
950 * I'm not sure what the second parameter is (the datatype is likely wrong), other then this:
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
)
962 TRACE("(%p,%s,%p)\n", hThemeFile
, unknown
, hWnd
);
963 hr
= UXTHEME_SetActiveTheme(hThemeFile
);
964 UXTHEME_broadcast_msg (NULL
, WM_THEMECHANGED
);
968 /**********************************************************************
969 * GetThemeDefaults (UXTHEME.7)
971 * Get the default color & size for a theme
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
982 * Failure: HRESULT error-code
984 HRESULT WINAPI
GetThemeDefaults(LPCWSTR pszThemeFileName
, LPWSTR pszColorName
,
985 DWORD dwColorNameLen
, LPWSTR pszSizeName
,
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
);
1004 /**********************************************************************
1005 * EnumThemes (UXTHEME.8)
1007 * Enumerate available themes, calls specified EnumThemeProc for each
1008 * theme found. Passes lpData through to callback function.
1011 * pszThemePath Path containing themes
1012 * callback Called for each theme found in path
1013 * lpData Passed through to callback
1017 * Failure: HRESULT error-code
1019 HRESULT WINAPI
EnumThemes(LPCWSTR pszThemePath
, EnumThemeProc callback
,
1022 WCHAR szDir
[MAX_PATH
];
1023 WCHAR szPath
[MAX_PATH
];
1027 WIN32_FIND_DATAW wfd
;
1031 TRACE("(%s,%p,%p)\n", debugstr_w(pszThemePath
), callback
, lpData
);
1033 if(!pszThemePath
|| !callback
)
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
) {
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
));
1057 hr
= GetThemeDocumentationProperty(szPath
, L
"tooltip", szTip
, ARRAY_SIZE(szTip
));
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");
1066 } while(FindNextFileW(hFind
, &wfd
));
1073 /**********************************************************************
1074 * EnumThemeColors (UXTHEME.9)
1076 * Enumerate theme colors available with a particular size
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
1087 * E_PROP_ID_UNSUPPORTED when dwColorName does not refer to a color
1088 * or when pszSizeName does not refer to a valid size
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
)
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
) {
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
));
1125 hr
= E_PROP_ID_UNSUPPORTED
;
1127 MSSTYLES_CloseThemeFile(pt
);
1131 /**********************************************************************
1132 * EnumThemeSizes (UXTHEME.10)
1134 * Enumerate theme colors available with a particular size
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
1145 * E_PROP_ID_UNSUPPORTED when dwSizeName does not refer to a size
1146 * or when pszColorName does not refer to a valid color
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
)
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
) {
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
));
1183 hr
= E_PROP_ID_UNSUPPORTED
;
1185 MSSTYLES_CloseThemeFile(pt
);
1189 /**********************************************************************
1190 * ParseThemeIniFile (UXTHEME.11)
1192 * Enumerate data in a theme INI file.
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
1202 * 0x800706488 (Unknown property) when enumeration is canceled from callback
1205 * When pszUnknown is NULL the callback is never called, the value does not seem to serve
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
));
1215 /**********************************************************************
1216 * CheckThemeSignature (UXTHEME.29)
1218 * Validates the signature of a theme file
1221 * pszIniFileName Path to a theme file
1225 * Failure: HRESULT error-code
1227 HRESULT WINAPI
CheckThemeSignature(LPCWSTR pszThemeFileName
)
1231 TRACE("(%s)\n", debugstr_w(pszThemeFileName
));
1232 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, NULL
, &pt
);
1235 MSSTYLES_CloseThemeFile(pt
);
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();
1256 /**********************************************************************
1257 * RefreshImmersiveColorPolicyState (UXTHEME.104)
1260 void WINAPI
RefreshImmersiveColorPolicyState(void)
1265 /**********************************************************************
1266 * ShouldSystemUseDarkMode (UXTHEME.138)
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)
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
);
1309 /**********************************************************************
1310 * SetPreferredAppMode (UXTHEME.135)
1313 int WINAPI
SetPreferredAppMode(int app_mode
)
1315 FIXME("%d: stub\n", app_mode
);