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 DECLSPEC_HIDDEN 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
);
134 /***********************************************************************
137 * Set the current active theme from the registry
139 static void UXTHEME_LoadTheme(void)
147 /* Get current theme configuration */
148 if(!RegOpenKeyW(HKEY_CURRENT_USER
, szThemeManager
, &hKey
)) {
149 TRACE("Loading theme config\n");
150 buffsize
= sizeof(tmp
);
151 if (!RegQueryValueExW(hKey
, L
"ThemeActive", NULL
, NULL
, (BYTE
*)tmp
, &buffsize
)) {
152 bThemeActive
= (tmp
[0] != '0');
155 bThemeActive
= FALSE
;
156 TRACE("Failed to get ThemeActive: %ld\n", GetLastError());
158 buffsize
= sizeof(szCurrentColor
);
159 if (RegQueryValueExW(hKey
, L
"ColorName", NULL
, NULL
, (BYTE
*)szCurrentColor
, &buffsize
))
160 szCurrentColor
[0] = '\0';
161 buffsize
= sizeof(szCurrentSize
);
162 if (RegQueryValueExW(hKey
, L
"SizeName", NULL
, NULL
, (BYTE
*)szCurrentSize
, &buffsize
))
163 szCurrentSize
[0] = '\0';
164 if (query_reg_path (hKey
, L
"DllName", szCurrentTheme
))
165 szCurrentTheme
[0] = '\0';
169 TRACE("Failed to open theme registry key\n");
172 /* Make sure the theme requested is actually valid */
173 hr
= MSSTYLES_OpenThemeFile(szCurrentTheme
,
174 szCurrentColor
[0]?szCurrentColor
:NULL
,
175 szCurrentSize
[0]?szCurrentSize
:NULL
,
178 bThemeActive
= FALSE
;
179 szCurrentTheme
[0] = '\0';
180 szCurrentColor
[0] = '\0';
181 szCurrentSize
[0] = '\0';
184 /* Make sure the global color & size match the theme */
185 lstrcpynW(szCurrentColor
, pt
->pszSelectedColor
, ARRAY_SIZE(szCurrentColor
));
186 lstrcpynW(szCurrentSize
, pt
->pszSelectedSize
, ARRAY_SIZE(szCurrentSize
));
188 UXTHEME_SetActiveTheme(pt
);
189 TRACE("Theme active: %s %s %s\n", debugstr_w(szCurrentTheme
),
190 debugstr_w(szCurrentColor
), debugstr_w(szCurrentSize
));
191 MSSTYLES_CloseThemeFile(pt
);
195 MSSTYLES_SetActiveTheme(NULL
, FALSE
);
196 TRACE("Theming not active\n");
200 /***********************************************************************/
202 static const WCHAR
* const SysColorsNames
[] =
204 L
"Scrollbar", /* COLOR_SCROLLBAR */
205 L
"Background", /* COLOR_BACKGROUND */
206 L
"ActiveTitle", /* COLOR_ACTIVECAPTION */
207 L
"InactiveTitle", /* COLOR_INACTIVECAPTION */
208 L
"Menu", /* COLOR_MENU */
209 L
"Window", /* COLOR_WINDOW */
210 L
"WindowFrame", /* COLOR_WINDOWFRAME */
211 L
"MenuText", /* COLOR_MENUTEXT */
212 L
"WindowText", /* COLOR_WINDOWTEXT */
213 L
"TitleText", /* COLOR_CAPTIONTEXT */
214 L
"ActiveBorder", /* COLOR_ACTIVEBORDER */
215 L
"InactiveBorder", /* COLOR_INACTIVEBORDER */
216 L
"AppWorkSpace", /* COLOR_APPWORKSPACE */
217 L
"Hilight", /* COLOR_HIGHLIGHT */
218 L
"HilightText", /* COLOR_HIGHLIGHTTEXT */
219 L
"ButtonFace", /* COLOR_BTNFACE */
220 L
"ButtonShadow", /* COLOR_BTNSHADOW */
221 L
"GrayText", /* COLOR_GRAYTEXT */
222 L
"ButtonText", /* COLOR_BTNTEXT */
223 L
"InactiveTitleText", /* COLOR_INACTIVECAPTIONTEXT */
224 L
"ButtonHilight", /* COLOR_BTNHIGHLIGHT */
225 L
"ButtonDkShadow", /* COLOR_3DDKSHADOW */
226 L
"ButtonLight", /* COLOR_3DLIGHT */
227 L
"InfoText", /* COLOR_INFOTEXT */
228 L
"InfoWindow", /* COLOR_INFOBK */
229 L
"ButtonAlternateFace", /* COLOR_ALTERNATEBTNFACE */
230 L
"HotTrackingColor", /* COLOR_HOTLIGHT */
231 L
"GradientActiveTitle", /* COLOR_GRADIENTACTIVECAPTION */
232 L
"GradientInactiveTitle", /* COLOR_GRADIENTINACTIVECAPTION */
233 L
"MenuHilight", /* COLOR_MENUHILIGHT */
234 L
"MenuBar", /* COLOR_MENUBAR */
237 static const WCHAR strColorKey
[] = L
"Control Panel\\Colors";
239 #define NUM_SYS_COLORS (COLOR_MENUBAR+1)
241 struct system_metrics
243 COLORREF system_colors
[NUM_SYS_COLORS
];
244 NONCLIENTMETRICSW non_client_metrics
;
245 LOGFONTW icon_title_font
;
246 DWORD gradient_caption
;
250 static BOOL
UXTHEME_GetSystemMetrics(struct system_metrics
*metrics
)
252 DPI_AWARENESS_CONTEXT old_context
;
256 for (i
= 0; i
< NUM_SYS_COLORS
; ++i
)
257 metrics
->system_colors
[i
] = GetSysColor(i
);
259 old_context
= SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE
);
261 memset(&metrics
->non_client_metrics
, 0, sizeof(metrics
->non_client_metrics
));
262 metrics
->non_client_metrics
.cbSize
= sizeof(metrics
->non_client_metrics
);
263 if (!SystemParametersInfoW(SPI_GETNONCLIENTMETRICS
, sizeof(metrics
->non_client_metrics
),
264 &metrics
->non_client_metrics
, 0))
266 memset(&metrics
->icon_title_font
, 0, sizeof(metrics
->icon_title_font
));
267 if (!SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, sizeof(metrics
->icon_title_font
),
268 &metrics
->icon_title_font
, 0))
270 if (!SystemParametersInfoW(SPI_GETGRADIENTCAPTIONS
, 0, &metrics
->gradient_caption
, 0))
272 if (!SystemParametersInfoW(SPI_GETFLATMENU
, 0, &metrics
->flat_menu
, 0))
277 SetThreadDpiAwarenessContext(old_context
);
281 /* Read back old settings after a theme was deactivated */
282 static BOOL
UXTHEME_GetUnthemedSystemMetrics(struct system_metrics
*metrics
)
284 HKEY theme_manager_key
= NULL
, color_key
= NULL
;
290 if (RegOpenKeyExW(HKEY_CURRENT_USER
, szThemeManager
, 0, KEY_QUERY_VALUE
, &theme_manager_key
))
293 if (RegOpenKeyExW(theme_manager_key
, strColorKey
, 0, KEY_QUERY_VALUE
, &color_key
))
296 for (i
= 0; i
< NUM_SYS_COLORS
; ++i
)
298 size
= sizeof(string
);
299 if (RegQueryValueExW(color_key
, SysColorsNames
[i
], 0, NULL
, (BYTE
*)string
, &size
))
302 if (swscanf(string
, L
"%d %d %d", &r
, &g
, &b
) != 3)
305 metrics
->system_colors
[i
] = RGB(r
, g
, b
);
308 size
= sizeof(metrics
->non_client_metrics
);
309 if (RegQueryValueExW(theme_manager_key
, L
"NonClientMetrics", 0, NULL
,
310 (BYTE
*)&metrics
->non_client_metrics
, &size
))
312 size
= sizeof(metrics
->icon_title_font
);
313 if (RegQueryValueExW(theme_manager_key
, L
"IconTitleFont", 0, NULL
,
314 (BYTE
*)&metrics
->icon_title_font
, &size
))
316 size
= sizeof(metrics
->gradient_caption
);
317 if (RegQueryValueExW(theme_manager_key
, L
"GradientCaption", 0, NULL
,
318 (BYTE
*)&metrics
->gradient_caption
, &size
))
320 size
= sizeof(metrics
->flat_menu
);
321 if (RegQueryValueExW(theme_manager_key
, L
"FlatMenu", 0, NULL
, (BYTE
*)&metrics
->flat_menu
,
327 RegCloseKey(color_key
);
328 RegCloseKey(theme_manager_key
);
332 static void UXTHEME_SaveUnthemedSystemMetrics(struct system_metrics
*metrics
)
334 HKEY theme_manager_key
, color_key
;
339 if (!RegCreateKeyExW(HKEY_CURRENT_USER
, szThemeManager
, 0, 0, 0, KEY_ALL_ACCESS
, 0,
340 &theme_manager_key
, 0))
342 if (!RegCreateKeyExW(theme_manager_key
, strColorKey
, 0, 0, 0, KEY_ALL_ACCESS
, 0, &color_key
,
345 for (i
= 0; i
< NUM_SYS_COLORS
; ++i
)
347 length
= swprintf(string
, ARRAY_SIZE(string
), L
"%d %d %d",
348 GetRValue(metrics
->system_colors
[i
]),
349 GetGValue(metrics
->system_colors
[i
]),
350 GetBValue(metrics
->system_colors
[i
]));
351 RegSetValueExW(color_key
, SysColorsNames
[i
], 0, REG_SZ
, (BYTE
*)string
,
352 (length
+ 1) * sizeof(WCHAR
));
355 RegCloseKey(color_key
);
358 RegSetValueExW(theme_manager_key
, L
"NonClientMetrics", 0, REG_BINARY
,
359 (BYTE
*)&metrics
->non_client_metrics
, sizeof(metrics
->non_client_metrics
));
360 RegSetValueExW(theme_manager_key
, L
"IconTitleFont", 0, REG_BINARY
,
361 (BYTE
*)&metrics
->icon_title_font
, sizeof(metrics
->icon_title_font
));
362 RegSetValueExW(theme_manager_key
, L
"GradientCaption", 0, REG_DWORD
,
363 (BYTE
*)&metrics
->gradient_caption
, sizeof(metrics
->gradient_caption
));
364 RegSetValueExW(theme_manager_key
, L
"FlatMenu", 0, REG_DWORD
, (BYTE
*)&metrics
->flat_menu
,
365 sizeof(metrics
->flat_menu
));
366 RegCloseKey(theme_manager_key
);
370 /* Make system settings persistent, so they're in effect even w/o uxtheme
372 * For efficiency reasons, only the last SystemParametersInfoW sets
373 * SPIF_SENDWININICHANGE */
374 static void UXTHEME_SaveSystemMetrics(struct system_metrics
*metrics
, BOOL send_syscolor_change
)
376 int i
, length
, index
[NUM_SYS_COLORS
];
377 DPI_AWARENESS_CONTEXT old_context
;
381 if (!RegCreateKeyExW(HKEY_CURRENT_USER
, strColorKey
, 0, 0, 0, KEY_ALL_ACCESS
, 0, &hkey
, 0))
383 for (i
= 0; i
< NUM_SYS_COLORS
; ++i
)
385 length
= swprintf(string
, ARRAY_SIZE(string
), L
"%d %d %d",
386 GetRValue(metrics
->system_colors
[i
]),
387 GetGValue(metrics
->system_colors
[i
]),
388 GetBValue(metrics
->system_colors
[i
]));
389 RegSetValueExW(hkey
, SysColorsNames
[i
], 0, REG_SZ
, (BYTE
*)string
,
390 (length
+ 1) * sizeof(WCHAR
));
395 if (send_syscolor_change
)
397 for (i
= 0; i
< NUM_SYS_COLORS
; ++i
)
400 SetSysColors(NUM_SYS_COLORS
, index
, metrics
->system_colors
);
403 old_context
= SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE
);
405 SystemParametersInfoW(SPI_SETNONCLIENTMETRICS
, sizeof(metrics
->non_client_metrics
),
406 &metrics
->non_client_metrics
, SPIF_UPDATEINIFILE
);
407 SystemParametersInfoW(SPI_SETICONTITLELOGFONT
, sizeof(metrics
->icon_title_font
),
408 &metrics
->icon_title_font
, SPIF_UPDATEINIFILE
);
409 SystemParametersInfoW(SPI_SETGRADIENTCAPTIONS
, 0, (void *)(INT_PTR
)metrics
->gradient_caption
,
411 SystemParametersInfoW(SPI_SETFLATMENU
, 0, (void *)(INT_PTR
)metrics
->flat_menu
,
412 SPIF_UPDATEINIFILE
| SPIF_SENDCHANGE
);
414 SetThreadDpiAwarenessContext(old_context
);
417 /***********************************************************************
418 * UXTHEME_SetActiveTheme
420 * Change the current active theme
422 HRESULT
UXTHEME_SetActiveTheme(PTHEME_FILE tf
)
424 BOOL ret
, loaded_before
= FALSE
, same_theme
= FALSE
;
425 struct system_metrics metrics
;
433 same_theme
= !lstrcmpW(szCurrentTheme
, tf
->szThemeFile
)
434 && !lstrcmpW(szCurrentColor
, tf
->pszSelectedColor
)
435 && !lstrcmpW(szCurrentSize
, tf
->pszSelectedSize
);
436 lstrcpynW(szCurrentTheme
, tf
->szThemeFile
, ARRAY_SIZE(szCurrentTheme
));
437 lstrcpynW(szCurrentColor
, tf
->pszSelectedColor
, ARRAY_SIZE(szCurrentColor
));
438 lstrcpynW(szCurrentSize
, tf
->pszSelectedSize
, ARRAY_SIZE(szCurrentSize
));
440 ret
= UXTHEME_GetSystemMetrics(&metrics
);
442 /* Check if theming is already active */
443 if (!RegOpenKeyW(HKEY_CURRENT_USER
, szThemeManager
, &hKey
))
446 if (!RegQueryValueExW(hKey
, L
"LoadedBefore", NULL
, NULL
, (BYTE
*)tmp
, &size
))
447 loaded_before
= (tmp
[0] != '0');
449 WARN("Failed to get LoadedBefore: %ld\n", GetLastError());
452 if (loaded_before
&& same_theme
)
453 return MSSTYLES_SetActiveTheme(tf
, FALSE
);
455 if (!loaded_before
&& ret
)
456 UXTHEME_SaveUnthemedSystemMetrics(&metrics
);
459 bThemeActive
= FALSE
;
460 szCurrentTheme
[0] = '\0';
461 szCurrentColor
[0] = '\0';
462 szCurrentSize
[0] = '\0';
465 TRACE("Writing theme config to registry\n");
466 if(!RegCreateKeyW(HKEY_CURRENT_USER
, szThemeManager
, &hKey
)) {
467 tmp
[0] = bThemeActive
?'1':'0';
469 RegSetValueExW(hKey
, L
"ThemeActive", 0, REG_SZ
, (const BYTE
*)tmp
, sizeof(WCHAR
)*2);
471 RegSetValueExW(hKey
, L
"ColorName", 0, REG_SZ
, (const BYTE
*)szCurrentColor
,
472 (lstrlenW(szCurrentColor
)+1)*sizeof(WCHAR
));
473 RegSetValueExW(hKey
, L
"SizeName", 0, REG_SZ
, (const BYTE
*)szCurrentSize
,
474 (lstrlenW(szCurrentSize
)+1)*sizeof(WCHAR
));
475 RegSetValueExW(hKey
, L
"DllName", 0, REG_SZ
, (const BYTE
*)szCurrentTheme
,
476 (lstrlenW(szCurrentTheme
)+1)*sizeof(WCHAR
));
477 RegSetValueExW(hKey
, L
"LoadedBefore", 0, REG_SZ
, (const BYTE
*)tmp
, sizeof(WCHAR
) * 2);
480 RegDeleteValueW(hKey
, L
"ColorName");
481 RegDeleteValueW(hKey
, L
"SizeName");
482 RegDeleteValueW(hKey
, L
"DllName");
483 RegDeleteValueW(hKey
, L
"LoadedBefore");
488 TRACE("Failed to open theme registry key\n");
490 hr
= MSSTYLES_SetActiveTheme(tf
, TRUE
);
493 if (UXTHEME_GetSystemMetrics(&metrics
))
494 UXTHEME_SaveSystemMetrics(&metrics
, FALSE
);
498 if (UXTHEME_GetUnthemedSystemMetrics(&metrics
))
499 UXTHEME_SaveSystemMetrics(&metrics
, TRUE
);
504 /***********************************************************************
507 void UXTHEME_InitSystem(HINSTANCE hInst
)
509 atWindowTheme
= GlobalAddAtomW(L
"ux_theme");
510 atSubAppName
= GlobalAddAtomW(L
"ux_subapp");
511 atSubIdList
= GlobalAddAtomW(L
"ux_subidlst");
512 atDialogThemeEnabled
= GlobalAddAtomW(L
"ux_dialogtheme");
518 void UXTHEME_UninitSystem(void)
521 MSSTYLES_SetActiveTheme(NULL
, FALSE
);
523 GlobalDeleteAtom(atWindowTheme
);
524 GlobalDeleteAtom(atSubAppName
);
525 GlobalDeleteAtom(atSubIdList
);
526 GlobalDeleteAtom(atDialogThemeEnabled
);
529 /***********************************************************************
530 * IsAppThemed (UXTHEME.@)
532 BOOL WINAPI
IsAppThemed(void)
534 return IsThemeActive();
537 /***********************************************************************
538 * IsThemeActive (UXTHEME.@)
540 BOOL WINAPI
IsThemeActive(void)
543 SetLastError(ERROR_SUCCESS
);
547 /************************************************************
548 * IsCompositionActive (UXTHEME.@)
550 BOOL WINAPI
IsCompositionActive(void)
554 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
559 /***********************************************************************
560 * EnableTheming (UXTHEME.@)
563 * This is a global and persistent change
565 HRESULT WINAPI
EnableTheming(BOOL fEnable
)
569 TRACE("(%d)\n", fEnable
);
571 if (bThemeActive
&& !fEnable
)
573 bThemeActive
= fEnable
;
574 if(!RegOpenKeyW(HKEY_CURRENT_USER
, szThemeManager
, &hKey
)) {
575 RegSetValueExW(hKey
, L
"ThemeActive", 0, REG_SZ
, (BYTE
*)L
"0", 2 * sizeof(WCHAR
));
578 UXTHEME_broadcast_msg (NULL
, WM_THEMECHANGED
);
583 /***********************************************************************
584 * UXTHEME_SetWindowProperty
586 * I'm using atoms as there may be large numbers of duplicated strings
587 * and they do the work of keeping memory down as a cause of that quite nicely
589 static HRESULT
UXTHEME_SetWindowProperty(HWND hwnd
, ATOM aProp
, LPCWSTR pszValue
)
591 ATOM oldValue
= (ATOM
)(size_t)RemovePropW(hwnd
, (LPCWSTR
)MAKEINTATOM(aProp
));
593 DeleteAtom(oldValue
);
595 ATOM atValue
= AddAtomW(pszValue
);
597 || !SetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(aProp
), (LPWSTR
)MAKEINTATOM(atValue
))) {
598 HRESULT hr
= HRESULT_FROM_WIN32(GetLastError());
599 if(atValue
) DeleteAtom(atValue
);
606 static LPWSTR
UXTHEME_GetWindowProperty(HWND hwnd
, ATOM aProp
, LPWSTR pszBuffer
, int dwLen
)
608 ATOM atValue
= (ATOM
)(size_t)GetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(aProp
));
610 if(GetAtomNameW(atValue
, pszBuffer
, dwLen
))
612 TRACE("property defined, but unable to get value\n");
617 static HTHEME
open_theme_data(HWND hwnd
, LPCWSTR pszClassList
, DWORD flags
, UINT dpi
)
619 WCHAR szAppBuff
[256];
620 WCHAR szClassBuff
[256];
622 LPCWSTR pszUseClassList
;
623 HTHEME hTheme
= NULL
;
624 TRACE("(%p,%s, %lx)\n", hwnd
, debugstr_w(pszClassList
), flags
);
628 SetLastError(E_POINTER
);
633 FIXME("unhandled flags: %lx\n", flags
);
637 pszAppName
= UXTHEME_GetWindowProperty(hwnd
, atSubAppName
, szAppBuff
, ARRAY_SIZE(szAppBuff
));
638 /* If SetWindowTheme was used on the window, that overrides the class list passed to this function */
639 pszUseClassList
= UXTHEME_GetWindowProperty(hwnd
, atSubIdList
, szClassBuff
, ARRAY_SIZE(szClassBuff
));
641 pszUseClassList
= pszClassList
;
644 hTheme
= MSSTYLES_OpenThemeClass(pszAppName
, pszUseClassList
, dpi
);
646 /* Fall back to default class if the specified subclass is not found */
648 hTheme
= MSSTYLES_OpenThemeClass(NULL
, pszUseClassList
, dpi
);
651 SetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(atWindowTheme
), hTheme
);
652 TRACE(" = %p\n", hTheme
);
654 SetLastError(hTheme
? ERROR_SUCCESS
: E_PROP_ID_UNSUPPORTED
);
658 /***********************************************************************
659 * OpenThemeDataEx (UXTHEME.61)
661 HTHEME WINAPI
OpenThemeDataEx(HWND hwnd
, LPCWSTR pszClassList
, DWORD flags
)
665 dpi
= GetDpiForWindow(hwnd
);
669 return open_theme_data(hwnd
, pszClassList
, flags
, dpi
);
672 /***********************************************************************
673 * OpenThemeDataForDpi (UXTHEME.@)
675 HTHEME WINAPI
OpenThemeDataForDpi(HWND hwnd
, LPCWSTR class_list
, UINT dpi
)
677 return open_theme_data(hwnd
, class_list
, 0, dpi
);
680 /***********************************************************************
681 * OpenThemeData (UXTHEME.@)
683 HTHEME WINAPI
OpenThemeData(HWND hwnd
, LPCWSTR classlist
)
685 return OpenThemeDataEx(hwnd
, classlist
, 0);
688 /***********************************************************************
689 * GetWindowTheme (UXTHEME.@)
691 * Retrieve the last theme opened for a window.
694 * hwnd [I] window to retrieve the theme for
697 * The most recent theme.
699 HTHEME WINAPI
GetWindowTheme(HWND hwnd
)
701 TRACE("(%p)\n", hwnd
);
705 SetLastError(E_HANDLE
);
709 return GetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(atWindowTheme
));
712 /***********************************************************************
713 * SetWindowTheme (UXTHEME.@)
715 * Persistent through the life of the window, even after themes change
717 HRESULT WINAPI
SetWindowTheme(HWND hwnd
, LPCWSTR pszSubAppName
,
718 LPCWSTR pszSubIdList
)
721 TRACE("(%p,%s,%s)\n", hwnd
, debugstr_w(pszSubAppName
),
722 debugstr_w(pszSubIdList
));
727 hr
= UXTHEME_SetWindowProperty(hwnd
, atSubAppName
, pszSubAppName
);
729 hr
= UXTHEME_SetWindowProperty(hwnd
, atSubIdList
, pszSubIdList
);
731 SendMessageW(hwnd
, WM_THEMECHANGED
, 0, 0);
735 /***********************************************************************
736 * SetWindowThemeAttribute (UXTHEME.@)
738 HRESULT WINAPI
SetWindowThemeAttribute(HWND hwnd
, enum WINDOWTHEMEATTRIBUTETYPE type
,
739 PVOID attribute
, DWORD size
)
741 FIXME("(%p,%d,%p,%ld): stub\n", hwnd
, type
, attribute
, size
);
745 /***********************************************************************
746 * GetCurrentThemeName (UXTHEME.@)
748 HRESULT WINAPI
GetCurrentThemeName(LPWSTR pszThemeFileName
, int dwMaxNameChars
,
749 LPWSTR pszColorBuff
, int cchMaxColorChars
,
750 LPWSTR pszSizeBuff
, int cchMaxSizeChars
)
753 return E_PROP_ID_UNSUPPORTED
;
754 if(pszThemeFileName
) lstrcpynW(pszThemeFileName
, szCurrentTheme
, dwMaxNameChars
);
755 if(pszColorBuff
) lstrcpynW(pszColorBuff
, szCurrentColor
, cchMaxColorChars
);
756 if(pszSizeBuff
) lstrcpynW(pszSizeBuff
, szCurrentSize
, cchMaxSizeChars
);
760 /***********************************************************************
761 * GetThemeAppProperties (UXTHEME.@)
763 DWORD WINAPI
GetThemeAppProperties(void)
765 return dwThemeAppProperties
;
768 /***********************************************************************
769 * SetThemeAppProperties (UXTHEME.@)
771 void WINAPI
SetThemeAppProperties(DWORD dwFlags
)
773 TRACE("(0x%08lx)\n", dwFlags
);
774 dwThemeAppProperties
= dwFlags
;
777 /***********************************************************************
778 * CloseThemeData (UXTHEME.@)
780 HRESULT WINAPI
CloseThemeData(HTHEME hTheme
)
782 TRACE("(%p)\n", hTheme
);
783 if(!hTheme
|| hTheme
== INVALID_HANDLE_VALUE
)
785 return MSSTYLES_CloseThemeClass(hTheme
);
788 /***********************************************************************
789 * HitTestThemeBackground (UXTHEME.@)
791 HRESULT WINAPI
HitTestThemeBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
792 int iStateId
, DWORD dwOptions
,
793 const RECT
*pRect
, HRGN hrgn
,
794 POINT ptTest
, WORD
*pwHitTestCode
)
796 FIXME("%d %d 0x%08lx: stub\n", iPartId
, iStateId
, dwOptions
);
802 /***********************************************************************
803 * IsThemePartDefined (UXTHEME.@)
805 BOOL WINAPI
IsThemePartDefined(HTHEME hTheme
, int iPartId
, int iStateId
)
807 TRACE("(%p,%d,%d)\n", hTheme
, iPartId
, iStateId
);
809 SetLastError(E_HANDLE
);
813 SetLastError(NO_ERROR
);
814 return !iStateId
&& MSSTYLES_FindPart(hTheme
, iPartId
);
817 /***********************************************************************
818 * GetThemeDocumentationProperty (UXTHEME.@)
820 * Try and retrieve the documentation property from string resources
821 * if that fails, get it from the [documentation] section of themes.ini
823 HRESULT WINAPI
GetThemeDocumentationProperty(LPCWSTR pszThemeName
,
824 LPCWSTR pszPropertyName
,
828 static const WORD wDocToRes
[] = {
829 TMT_DISPLAYNAME
,5000,
843 TRACE("(%s,%s,%p,%d)\n", debugstr_w(pszThemeName
), debugstr_w(pszPropertyName
),
844 pszValueBuff
, cchMaxValChars
);
846 hr
= MSSTYLES_OpenThemeFile(pszThemeName
, NULL
, NULL
, &pt
);
847 if(FAILED(hr
)) return hr
;
849 /* Try to load from string resources */
850 hr
= E_PROP_ID_UNSUPPORTED
;
851 if(MSSTYLES_LookupProperty(pszPropertyName
, NULL
, &iDocId
)) {
852 for(i
=0; i
<ARRAY_SIZE(wDocToRes
); i
+=2) {
853 if(wDocToRes
[i
] == iDocId
) {
854 if(LoadStringW(pt
->hTheme
, wDocToRes
[i
+1], pszValueBuff
, cchMaxValChars
)) {
861 /* If loading from string resource failed, try getting it from the theme.ini */
863 PUXINI_FILE uf
= MSSTYLES_GetThemeIni(pt
);
864 if(UXINI_FindSection(uf
, L
"documentation")) {
867 if(UXINI_FindValue(uf
, pszPropertyName
, &lpValue
, &dwLen
)) {
868 lstrcpynW(pszValueBuff
, lpValue
, min(dwLen
+1,cchMaxValChars
));
875 MSSTYLES_CloseThemeFile(pt
);
879 /**********************************************************************
880 * Undocumented functions
883 /**********************************************************************
884 * QueryThemeServices (UXTHEME.1)
887 * some kind of status flag
889 DWORD WINAPI
QueryThemeServices(void)
892 return 3; /* This is what is returned under XP in most cases */
896 /**********************************************************************
897 * OpenThemeFile (UXTHEME.2)
899 * Opens a theme file, which can be used to change the current theme, etc
902 * pszThemeFileName Path to a msstyles theme file
903 * pszColorName Color defined in the theme, eg. NormalColor
904 * pszSizeName Size defined in the theme, eg. NormalSize
905 * hThemeFile Handle to theme file
909 * Failure: HRESULT error-code
911 HRESULT WINAPI
OpenThemeFile(LPCWSTR pszThemeFileName
, LPCWSTR pszColorName
,
912 LPCWSTR pszSizeName
, HTHEMEFILE
*hThemeFile
,
915 TRACE("(%s,%s,%s,%p,%ld)\n", debugstr_w(pszThemeFileName
),
916 debugstr_w(pszColorName
), debugstr_w(pszSizeName
),
917 hThemeFile
, unknown
);
918 return MSSTYLES_OpenThemeFile(pszThemeFileName
, pszColorName
, pszSizeName
, (PTHEME_FILE
*)hThemeFile
);
921 /**********************************************************************
922 * CloseThemeFile (UXTHEME.3)
924 * Releases theme file handle returned by OpenThemeFile
927 * hThemeFile Handle to theme file
931 * Failure: HRESULT error-code
933 HRESULT WINAPI
CloseThemeFile(HTHEMEFILE hThemeFile
)
935 TRACE("(%p)\n", hThemeFile
);
936 MSSTYLES_CloseThemeFile(hThemeFile
);
940 /**********************************************************************
941 * ApplyTheme (UXTHEME.4)
943 * Set a theme file to be the currently active theme
946 * hThemeFile Handle to theme file
948 * hWnd Window requesting the theme change
952 * Failure: HRESULT error-code
955 * I'm not sure what the second parameter is (the datatype is likely wrong), other then this:
958 * the theme is applied with the screen redrawing really badly (flickers)
959 * char b[] = "\0"; where \0 can be one or more of any character, makes no difference
960 * the theme is applied smoothly (screen does not flicker)
961 * char *b = "\0" or NULL; where \0 can be zero or more of any character, makes no difference
962 * the function fails returning invalid parameter... very strange
964 HRESULT WINAPI
ApplyTheme(HTHEMEFILE hThemeFile
, char *unknown
, HWND hWnd
)
967 TRACE("(%p,%s,%p)\n", hThemeFile
, unknown
, hWnd
);
968 hr
= UXTHEME_SetActiveTheme(hThemeFile
);
969 UXTHEME_broadcast_msg (NULL
, WM_THEMECHANGED
);
973 /**********************************************************************
974 * GetThemeDefaults (UXTHEME.7)
976 * Get the default color & size for a theme
979 * pszThemeFileName Path to a msstyles theme file
980 * pszColorName Buffer to receive the default color name
981 * dwColorNameLen Length, in characters, of color name buffer
982 * pszSizeName Buffer to receive the default size name
983 * dwSizeNameLen Length, in characters, of size name buffer
987 * Failure: HRESULT error-code
989 HRESULT WINAPI
GetThemeDefaults(LPCWSTR pszThemeFileName
, LPWSTR pszColorName
,
990 DWORD dwColorNameLen
, LPWSTR pszSizeName
,
995 TRACE("(%s,%p,%ld,%p,%ld)\n", debugstr_w(pszThemeFileName
),
996 pszColorName
, dwColorNameLen
,
997 pszSizeName
, dwSizeNameLen
);
999 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, NULL
, &pt
);
1000 if(FAILED(hr
)) return hr
;
1002 lstrcpynW(pszColorName
, pt
->pszSelectedColor
, dwColorNameLen
);
1003 lstrcpynW(pszSizeName
, pt
->pszSelectedSize
, dwSizeNameLen
);
1005 MSSTYLES_CloseThemeFile(pt
);
1009 /**********************************************************************
1010 * EnumThemes (UXTHEME.8)
1012 * Enumerate available themes, calls specified EnumThemeProc for each
1013 * theme found. Passes lpData through to callback function.
1016 * pszThemePath Path containing themes
1017 * callback Called for each theme found in path
1018 * lpData Passed through to callback
1022 * Failure: HRESULT error-code
1024 HRESULT WINAPI
EnumThemes(LPCWSTR pszThemePath
, EnumThemeProc callback
,
1027 WCHAR szDir
[MAX_PATH
];
1028 WCHAR szPath
[MAX_PATH
];
1032 WIN32_FIND_DATAW wfd
;
1036 TRACE("(%s,%p,%p)\n", debugstr_w(pszThemePath
), callback
, lpData
);
1038 if(!pszThemePath
|| !callback
)
1041 lstrcpyW(szDir
, pszThemePath
);
1042 pathLen
= lstrlenW (szDir
);
1043 if ((pathLen
> 0) && (pathLen
< MAX_PATH
-1) && (szDir
[pathLen
- 1] != '\\'))
1045 szDir
[pathLen
] = '\\';
1046 szDir
[pathLen
+1] = 0;
1049 lstrcpyW(szPath
, szDir
);
1050 lstrcatW(szPath
, L
"*.*");
1051 TRACE("searching %s\n", debugstr_w(szPath
));
1053 hFind
= FindFirstFileW(szPath
, &wfd
);
1054 if(hFind
!= INVALID_HANDLE_VALUE
) {
1056 if(wfd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
1057 && !(wfd
.cFileName
[0] == '.' && ((wfd
.cFileName
[1] == '.' && wfd
.cFileName
[2] == 0) || wfd
.cFileName
[1] == 0))) {
1058 wsprintfW(szPath
, L
"%s%s\\%s.msstyles", szDir
, wfd
.cFileName
, wfd
.cFileName
);
1060 hr
= GetThemeDocumentationProperty(szPath
, L
"displayname", szName
, ARRAY_SIZE(szName
));
1062 hr
= GetThemeDocumentationProperty(szPath
, L
"tooltip", szTip
, ARRAY_SIZE(szTip
));
1064 TRACE("callback(%s,%s,%s,%p)\n", debugstr_w(szPath
), debugstr_w(szName
), debugstr_w(szTip
), lpData
);
1065 if(!callback(NULL
, szPath
, szName
, szTip
, NULL
, lpData
)) {
1066 TRACE("callback ended enum\n");
1071 } while(FindNextFileW(hFind
, &wfd
));
1078 /**********************************************************************
1079 * EnumThemeColors (UXTHEME.9)
1081 * Enumerate theme colors available with a particular size
1084 * pszThemeFileName Path to a msstyles theme file
1085 * pszSizeName Theme size to enumerate available colors
1086 * If NULL the default theme size is used
1087 * dwColorNum Color index to retrieve, increment from 0
1088 * pszColorNames Output color names
1092 * E_PROP_ID_UNSUPPORTED when dwColorName does not refer to a color
1093 * or when pszSizeName does not refer to a valid size
1096 * XP fails with E_POINTER when pszColorNames points to a buffer smaller than
1097 * sizeof(THEMENAMES).
1099 * Not very efficient that I'm opening & validating the theme every call, but
1100 * this is undocumented and almost never called..
1101 * (and this is how windows works too)
1103 HRESULT WINAPI
EnumThemeColors(LPWSTR pszThemeFileName
, LPWSTR pszSizeName
,
1104 DWORD dwColorNum
, PTHEMENAMES pszColorNames
)
1109 UINT resourceId
= dwColorNum
+ 1000;
1110 TRACE("(%s,%s,%ld)\n", debugstr_w(pszThemeFileName
),
1111 debugstr_w(pszSizeName
), dwColorNum
);
1113 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, pszSizeName
, &pt
);
1114 if(FAILED(hr
)) return hr
;
1116 tmp
= pt
->pszAvailColors
;
1117 while(dwColorNum
&& *tmp
) {
1119 tmp
+= lstrlenW(tmp
)+1;
1121 if(!dwColorNum
&& *tmp
) {
1122 TRACE("%s\n", debugstr_w(tmp
));
1123 lstrcpyW(pszColorNames
->szName
, tmp
);
1124 LoadStringW(pt
->hTheme
, resourceId
, pszColorNames
->szDisplayName
,
1125 ARRAY_SIZE(pszColorNames
->szDisplayName
));
1126 LoadStringW(pt
->hTheme
, resourceId
+1000, pszColorNames
->szTooltip
,
1127 ARRAY_SIZE(pszColorNames
->szTooltip
));
1130 hr
= E_PROP_ID_UNSUPPORTED
;
1132 MSSTYLES_CloseThemeFile(pt
);
1136 /**********************************************************************
1137 * EnumThemeSizes (UXTHEME.10)
1139 * Enumerate theme colors available with a particular size
1142 * pszThemeFileName Path to a msstyles theme file
1143 * pszColorName Theme color to enumerate available sizes
1144 * If NULL the default theme color is used
1145 * dwSizeNum Size index to retrieve, increment from 0
1146 * pszSizeNames Output size names
1150 * E_PROP_ID_UNSUPPORTED when dwSizeName does not refer to a size
1151 * or when pszColorName does not refer to a valid color
1154 * XP fails with E_POINTER when pszSizeNames points to a buffer smaller than
1155 * sizeof(THEMENAMES).
1157 * Not very efficient that I'm opening & validating the theme every call, but
1158 * this is undocumented and almost never called..
1159 * (and this is how windows works too)
1161 HRESULT WINAPI
EnumThemeSizes(LPWSTR pszThemeFileName
, LPWSTR pszColorName
,
1162 DWORD dwSizeNum
, PTHEMENAMES pszSizeNames
)
1167 UINT resourceId
= dwSizeNum
+ 3000;
1168 TRACE("(%s,%s,%ld)\n", debugstr_w(pszThemeFileName
),
1169 debugstr_w(pszColorName
), dwSizeNum
);
1171 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, pszColorName
, NULL
, &pt
);
1172 if(FAILED(hr
)) return hr
;
1174 tmp
= pt
->pszAvailSizes
;
1175 while(dwSizeNum
&& *tmp
) {
1177 tmp
+= lstrlenW(tmp
)+1;
1179 if(!dwSizeNum
&& *tmp
) {
1180 TRACE("%s\n", debugstr_w(tmp
));
1181 lstrcpyW(pszSizeNames
->szName
, tmp
);
1182 LoadStringW(pt
->hTheme
, resourceId
, pszSizeNames
->szDisplayName
,
1183 ARRAY_SIZE(pszSizeNames
->szDisplayName
));
1184 LoadStringW(pt
->hTheme
, resourceId
+1000, pszSizeNames
->szTooltip
,
1185 ARRAY_SIZE(pszSizeNames
->szTooltip
));
1188 hr
= E_PROP_ID_UNSUPPORTED
;
1190 MSSTYLES_CloseThemeFile(pt
);
1194 /**********************************************************************
1195 * ParseThemeIniFile (UXTHEME.11)
1197 * Enumerate data in a theme INI file.
1200 * pszIniFileName Path to a theme ini file
1201 * pszUnknown Cannot be NULL, L"" is valid
1202 * callback Called for each found entry
1203 * lpData Passed through to callback
1207 * 0x800706488 (Unknown property) when enumeration is canceled from callback
1210 * When pszUnknown is NULL the callback is never called, the value does not seem to serve
1213 HRESULT WINAPI
ParseThemeIniFile(LPCWSTR pszIniFileName
, LPWSTR pszUnknown
,
1214 ParseThemeIniFileProc callback
, LPVOID lpData
)
1216 FIXME("%s %s: stub\n", debugstr_w(pszIniFileName
), debugstr_w(pszUnknown
));
1220 /**********************************************************************
1221 * CheckThemeSignature (UXTHEME.29)
1223 * Validates the signature of a theme file
1226 * pszIniFileName Path to a theme file
1230 * Failure: HRESULT error-code
1232 HRESULT WINAPI
CheckThemeSignature(LPCWSTR pszThemeFileName
)
1236 TRACE("(%s)\n", debugstr_w(pszThemeFileName
));
1237 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, NULL
, &pt
);
1240 MSSTYLES_CloseThemeFile(pt
);
1244 BOOL WINAPI
ThemeHooksInstall(void)
1246 struct user_api_hook hooks
;
1248 hooks
.pDefDlgProc
= UXTHEME_DefDlgProc
;
1249 hooks
.pScrollBarDraw
= UXTHEME_ScrollBarDraw
;
1250 hooks
.pScrollBarWndProc
= UXTHEME_ScrollbarWndProc
;
1251 return RegisterUserApiHook(&hooks
, &user_api
);
1254 BOOL WINAPI
ThemeHooksRemove(void)
1256 UnregisterUserApiHook();