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
);
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
);
645 /* Fall back to default class if the specified subclass is not found */
647 hTheme
= MSSTYLES_OpenThemeClass(NULL
, pszUseClassList
, dpi
);
650 SetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(atWindowTheme
), hTheme
);
651 TRACE(" = %p\n", hTheme
);
653 SetLastError(hTheme
? ERROR_SUCCESS
: E_PROP_ID_UNSUPPORTED
);
657 /***********************************************************************
658 * OpenThemeDataEx (UXTHEME.61)
660 HTHEME WINAPI
OpenThemeDataEx(HWND hwnd
, LPCWSTR pszClassList
, DWORD flags
)
664 dpi
= GetDpiForWindow(hwnd
);
666 dpi
= GetDpiForSystem();
668 return open_theme_data(hwnd
, pszClassList
, flags
, dpi
);
671 /***********************************************************************
672 * OpenThemeDataForDpi (UXTHEME.@)
674 HTHEME WINAPI
OpenThemeDataForDpi(HWND hwnd
, LPCWSTR class_list
, UINT dpi
)
676 return open_theme_data(hwnd
, class_list
, 0, dpi
);
679 /***********************************************************************
680 * OpenThemeData (UXTHEME.@)
682 HTHEME WINAPI
OpenThemeData(HWND hwnd
, LPCWSTR classlist
)
684 return OpenThemeDataEx(hwnd
, classlist
, 0);
687 /***********************************************************************
688 * GetWindowTheme (UXTHEME.@)
690 * Retrieve the last theme opened for a window.
693 * hwnd [I] window to retrieve the theme for
696 * The most recent theme.
698 HTHEME WINAPI
GetWindowTheme(HWND hwnd
)
700 TRACE("(%p)\n", hwnd
);
704 SetLastError(E_HANDLE
);
708 return GetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(atWindowTheme
));
711 /***********************************************************************
712 * SetWindowTheme (UXTHEME.@)
714 * Persistent through the life of the window, even after themes change
716 HRESULT WINAPI
SetWindowTheme(HWND hwnd
, LPCWSTR pszSubAppName
,
717 LPCWSTR pszSubIdList
)
720 TRACE("(%p,%s,%s)\n", hwnd
, debugstr_w(pszSubAppName
),
721 debugstr_w(pszSubIdList
));
726 hr
= UXTHEME_SetWindowProperty(hwnd
, atSubAppName
, pszSubAppName
);
728 hr
= UXTHEME_SetWindowProperty(hwnd
, atSubIdList
, pszSubIdList
);
730 SendMessageW(hwnd
, WM_THEMECHANGED
, 0, 0);
734 /***********************************************************************
735 * SetWindowThemeAttribute (UXTHEME.@)
737 HRESULT WINAPI
SetWindowThemeAttribute(HWND hwnd
, enum WINDOWTHEMEATTRIBUTETYPE type
,
738 PVOID attribute
, DWORD size
)
740 FIXME("(%p,%d,%p,%ld): stub\n", hwnd
, type
, attribute
, size
);
744 /***********************************************************************
745 * GetCurrentThemeName (UXTHEME.@)
747 HRESULT WINAPI
GetCurrentThemeName(LPWSTR pszThemeFileName
, int dwMaxNameChars
,
748 LPWSTR pszColorBuff
, int cchMaxColorChars
,
749 LPWSTR pszSizeBuff
, int cchMaxSizeChars
)
752 return E_PROP_ID_UNSUPPORTED
;
753 if(pszThemeFileName
) lstrcpynW(pszThemeFileName
, szCurrentTheme
, dwMaxNameChars
);
754 if(pszColorBuff
) lstrcpynW(pszColorBuff
, szCurrentColor
, cchMaxColorChars
);
755 if(pszSizeBuff
) lstrcpynW(pszSizeBuff
, szCurrentSize
, cchMaxSizeChars
);
759 /***********************************************************************
760 * GetThemeAppProperties (UXTHEME.@)
762 DWORD WINAPI
GetThemeAppProperties(void)
764 return dwThemeAppProperties
;
767 /***********************************************************************
768 * SetThemeAppProperties (UXTHEME.@)
770 void WINAPI
SetThemeAppProperties(DWORD dwFlags
)
772 TRACE("(0x%08lx)\n", dwFlags
);
773 dwThemeAppProperties
= dwFlags
;
776 /***********************************************************************
777 * CloseThemeData (UXTHEME.@)
779 HRESULT WINAPI
CloseThemeData(HTHEME hTheme
)
781 TRACE("(%p)\n", hTheme
);
782 if(!hTheme
|| hTheme
== INVALID_HANDLE_VALUE
)
784 return MSSTYLES_CloseThemeClass(hTheme
);
787 /***********************************************************************
788 * HitTestThemeBackground (UXTHEME.@)
790 HRESULT WINAPI
HitTestThemeBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
791 int iStateId
, DWORD dwOptions
,
792 const RECT
*pRect
, HRGN hrgn
,
793 POINT ptTest
, WORD
*pwHitTestCode
)
795 FIXME("%d %d 0x%08lx: stub\n", iPartId
, iStateId
, dwOptions
);
801 /***********************************************************************
802 * IsThemePartDefined (UXTHEME.@)
804 BOOL WINAPI
IsThemePartDefined(HTHEME hTheme
, int iPartId
, int iStateId
)
806 TRACE("(%p,%d,%d)\n", hTheme
, iPartId
, iStateId
);
808 SetLastError(E_HANDLE
);
812 SetLastError(NO_ERROR
);
813 return !iStateId
&& MSSTYLES_FindPart(hTheme
, iPartId
);
816 /***********************************************************************
817 * GetThemeDocumentationProperty (UXTHEME.@)
819 * Try and retrieve the documentation property from string resources
820 * if that fails, get it from the [documentation] section of themes.ini
822 HRESULT WINAPI
GetThemeDocumentationProperty(LPCWSTR pszThemeName
,
823 LPCWSTR pszPropertyName
,
827 static const WORD wDocToRes
[] = {
828 TMT_DISPLAYNAME
,5000,
842 TRACE("(%s,%s,%p,%d)\n", debugstr_w(pszThemeName
), debugstr_w(pszPropertyName
),
843 pszValueBuff
, cchMaxValChars
);
845 hr
= MSSTYLES_OpenThemeFile(pszThemeName
, NULL
, NULL
, &pt
);
846 if(FAILED(hr
)) return hr
;
848 /* Try to load from string resources */
849 hr
= E_PROP_ID_UNSUPPORTED
;
850 if(MSSTYLES_LookupProperty(pszPropertyName
, NULL
, &iDocId
)) {
851 for(i
=0; i
<ARRAY_SIZE(wDocToRes
); i
+=2) {
852 if(wDocToRes
[i
] == iDocId
) {
853 if(LoadStringW(pt
->hTheme
, wDocToRes
[i
+1], pszValueBuff
, cchMaxValChars
)) {
860 /* If loading from string resource failed, try getting it from the theme.ini */
862 PUXINI_FILE uf
= MSSTYLES_GetThemeIni(pt
);
863 if(UXINI_FindSection(uf
, L
"documentation")) {
866 if(UXINI_FindValue(uf
, pszPropertyName
, &lpValue
, &dwLen
)) {
867 lstrcpynW(pszValueBuff
, lpValue
, min(dwLen
+1,cchMaxValChars
));
874 MSSTYLES_CloseThemeFile(pt
);
878 /**********************************************************************
879 * Undocumented functions
882 /**********************************************************************
883 * QueryThemeServices (UXTHEME.1)
886 * some kind of status flag
888 DWORD WINAPI
QueryThemeServices(void)
891 return 3; /* This is what is returned under XP in most cases */
895 /**********************************************************************
896 * OpenThemeFile (UXTHEME.2)
898 * Opens a theme file, which can be used to change the current theme, etc
901 * pszThemeFileName Path to a msstyles theme file
902 * pszColorName Color defined in the theme, eg. NormalColor
903 * pszSizeName Size defined in the theme, eg. NormalSize
904 * hThemeFile Handle to theme file
908 * Failure: HRESULT error-code
910 HRESULT WINAPI
OpenThemeFile(LPCWSTR pszThemeFileName
, LPCWSTR pszColorName
,
911 LPCWSTR pszSizeName
, HTHEMEFILE
*hThemeFile
,
914 TRACE("(%s,%s,%s,%p,%ld)\n", debugstr_w(pszThemeFileName
),
915 debugstr_w(pszColorName
), debugstr_w(pszSizeName
),
916 hThemeFile
, unknown
);
917 return MSSTYLES_OpenThemeFile(pszThemeFileName
, pszColorName
, pszSizeName
, (PTHEME_FILE
*)hThemeFile
);
920 /**********************************************************************
921 * CloseThemeFile (UXTHEME.3)
923 * Releases theme file handle returned by OpenThemeFile
926 * hThemeFile Handle to theme file
930 * Failure: HRESULT error-code
932 HRESULT WINAPI
CloseThemeFile(HTHEMEFILE hThemeFile
)
934 TRACE("(%p)\n", hThemeFile
);
935 MSSTYLES_CloseThemeFile(hThemeFile
);
939 /**********************************************************************
940 * ApplyTheme (UXTHEME.4)
942 * Set a theme file to be the currently active theme
945 * hThemeFile Handle to theme file
947 * hWnd Window requesting the theme change
951 * Failure: HRESULT error-code
954 * I'm not sure what the second parameter is (the datatype is likely wrong), other then this:
957 * the theme is applied with the screen redrawing really badly (flickers)
958 * char b[] = "\0"; where \0 can be one or more of any character, makes no difference
959 * the theme is applied smoothly (screen does not flicker)
960 * char *b = "\0" or NULL; where \0 can be zero or more of any character, makes no difference
961 * the function fails returning invalid parameter... very strange
963 HRESULT WINAPI
ApplyTheme(HTHEMEFILE hThemeFile
, char *unknown
, HWND hWnd
)
966 TRACE("(%p,%s,%p)\n", hThemeFile
, unknown
, hWnd
);
967 hr
= UXTHEME_SetActiveTheme(hThemeFile
);
968 UXTHEME_broadcast_msg (NULL
, WM_THEMECHANGED
);
972 /**********************************************************************
973 * GetThemeDefaults (UXTHEME.7)
975 * Get the default color & size for a theme
978 * pszThemeFileName Path to a msstyles theme file
979 * pszColorName Buffer to receive the default color name
980 * dwColorNameLen Length, in characters, of color name buffer
981 * pszSizeName Buffer to receive the default size name
982 * dwSizeNameLen Length, in characters, of size name buffer
986 * Failure: HRESULT error-code
988 HRESULT WINAPI
GetThemeDefaults(LPCWSTR pszThemeFileName
, LPWSTR pszColorName
,
989 DWORD dwColorNameLen
, LPWSTR pszSizeName
,
994 TRACE("(%s,%p,%ld,%p,%ld)\n", debugstr_w(pszThemeFileName
),
995 pszColorName
, dwColorNameLen
,
996 pszSizeName
, dwSizeNameLen
);
998 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, NULL
, &pt
);
999 if(FAILED(hr
)) return hr
;
1001 lstrcpynW(pszColorName
, pt
->pszSelectedColor
, dwColorNameLen
);
1002 lstrcpynW(pszSizeName
, pt
->pszSelectedSize
, dwSizeNameLen
);
1004 MSSTYLES_CloseThemeFile(pt
);
1008 /**********************************************************************
1009 * EnumThemes (UXTHEME.8)
1011 * Enumerate available themes, calls specified EnumThemeProc for each
1012 * theme found. Passes lpData through to callback function.
1015 * pszThemePath Path containing themes
1016 * callback Called for each theme found in path
1017 * lpData Passed through to callback
1021 * Failure: HRESULT error-code
1023 HRESULT WINAPI
EnumThemes(LPCWSTR pszThemePath
, EnumThemeProc callback
,
1026 WCHAR szDir
[MAX_PATH
];
1027 WCHAR szPath
[MAX_PATH
];
1031 WIN32_FIND_DATAW wfd
;
1035 TRACE("(%s,%p,%p)\n", debugstr_w(pszThemePath
), callback
, lpData
);
1037 if(!pszThemePath
|| !callback
)
1040 lstrcpyW(szDir
, pszThemePath
);
1041 pathLen
= lstrlenW (szDir
);
1042 if ((pathLen
> 0) && (pathLen
< MAX_PATH
-1) && (szDir
[pathLen
- 1] != '\\'))
1044 szDir
[pathLen
] = '\\';
1045 szDir
[pathLen
+1] = 0;
1048 lstrcpyW(szPath
, szDir
);
1049 lstrcatW(szPath
, L
"*.*");
1050 TRACE("searching %s\n", debugstr_w(szPath
));
1052 hFind
= FindFirstFileW(szPath
, &wfd
);
1053 if(hFind
!= INVALID_HANDLE_VALUE
) {
1055 if(wfd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
1056 && !(wfd
.cFileName
[0] == '.' && ((wfd
.cFileName
[1] == '.' && wfd
.cFileName
[2] == 0) || wfd
.cFileName
[1] == 0))) {
1057 wsprintfW(szPath
, L
"%s%s\\%s.msstyles", szDir
, wfd
.cFileName
, wfd
.cFileName
);
1059 hr
= GetThemeDocumentationProperty(szPath
, L
"displayname", szName
, ARRAY_SIZE(szName
));
1061 hr
= GetThemeDocumentationProperty(szPath
, L
"tooltip", szTip
, ARRAY_SIZE(szTip
));
1063 TRACE("callback(%s,%s,%s,%p)\n", debugstr_w(szPath
), debugstr_w(szName
), debugstr_w(szTip
), lpData
);
1064 if(!callback(NULL
, szPath
, szName
, szTip
, NULL
, lpData
)) {
1065 TRACE("callback ended enum\n");
1070 } while(FindNextFileW(hFind
, &wfd
));
1077 /**********************************************************************
1078 * EnumThemeColors (UXTHEME.9)
1080 * Enumerate theme colors available with a particular size
1083 * pszThemeFileName Path to a msstyles theme file
1084 * pszSizeName Theme size to enumerate available colors
1085 * If NULL the default theme size is used
1086 * dwColorNum Color index to retrieve, increment from 0
1087 * pszColorNames Output color names
1091 * E_PROP_ID_UNSUPPORTED when dwColorName does not refer to a color
1092 * or when pszSizeName does not refer to a valid size
1095 * XP fails with E_POINTER when pszColorNames points to a buffer smaller than
1096 * sizeof(THEMENAMES).
1098 * Not very efficient that I'm opening & validating the theme every call, but
1099 * this is undocumented and almost never called..
1100 * (and this is how windows works too)
1102 HRESULT WINAPI
EnumThemeColors(LPWSTR pszThemeFileName
, LPWSTR pszSizeName
,
1103 DWORD dwColorNum
, PTHEMENAMES pszColorNames
)
1108 UINT resourceId
= dwColorNum
+ 1000;
1109 TRACE("(%s,%s,%ld)\n", debugstr_w(pszThemeFileName
),
1110 debugstr_w(pszSizeName
), dwColorNum
);
1112 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, pszSizeName
, &pt
);
1113 if(FAILED(hr
)) return hr
;
1115 tmp
= pt
->pszAvailColors
;
1116 while(dwColorNum
&& *tmp
) {
1118 tmp
+= lstrlenW(tmp
)+1;
1120 if(!dwColorNum
&& *tmp
) {
1121 TRACE("%s\n", debugstr_w(tmp
));
1122 lstrcpyW(pszColorNames
->szName
, tmp
);
1123 LoadStringW(pt
->hTheme
, resourceId
, pszColorNames
->szDisplayName
,
1124 ARRAY_SIZE(pszColorNames
->szDisplayName
));
1125 LoadStringW(pt
->hTheme
, resourceId
+1000, pszColorNames
->szTooltip
,
1126 ARRAY_SIZE(pszColorNames
->szTooltip
));
1129 hr
= E_PROP_ID_UNSUPPORTED
;
1131 MSSTYLES_CloseThemeFile(pt
);
1135 /**********************************************************************
1136 * EnumThemeSizes (UXTHEME.10)
1138 * Enumerate theme colors available with a particular size
1141 * pszThemeFileName Path to a msstyles theme file
1142 * pszColorName Theme color to enumerate available sizes
1143 * If NULL the default theme color is used
1144 * dwSizeNum Size index to retrieve, increment from 0
1145 * pszSizeNames Output size names
1149 * E_PROP_ID_UNSUPPORTED when dwSizeName does not refer to a size
1150 * or when pszColorName does not refer to a valid color
1153 * XP fails with E_POINTER when pszSizeNames points to a buffer smaller than
1154 * sizeof(THEMENAMES).
1156 * Not very efficient that I'm opening & validating the theme every call, but
1157 * this is undocumented and almost never called..
1158 * (and this is how windows works too)
1160 HRESULT WINAPI
EnumThemeSizes(LPWSTR pszThemeFileName
, LPWSTR pszColorName
,
1161 DWORD dwSizeNum
, PTHEMENAMES pszSizeNames
)
1166 UINT resourceId
= dwSizeNum
+ 3000;
1167 TRACE("(%s,%s,%ld)\n", debugstr_w(pszThemeFileName
),
1168 debugstr_w(pszColorName
), dwSizeNum
);
1170 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, pszColorName
, NULL
, &pt
);
1171 if(FAILED(hr
)) return hr
;
1173 tmp
= pt
->pszAvailSizes
;
1174 while(dwSizeNum
&& *tmp
) {
1176 tmp
+= lstrlenW(tmp
)+1;
1178 if(!dwSizeNum
&& *tmp
) {
1179 TRACE("%s\n", debugstr_w(tmp
));
1180 lstrcpyW(pszSizeNames
->szName
, tmp
);
1181 LoadStringW(pt
->hTheme
, resourceId
, pszSizeNames
->szDisplayName
,
1182 ARRAY_SIZE(pszSizeNames
->szDisplayName
));
1183 LoadStringW(pt
->hTheme
, resourceId
+1000, pszSizeNames
->szTooltip
,
1184 ARRAY_SIZE(pszSizeNames
->szTooltip
));
1187 hr
= E_PROP_ID_UNSUPPORTED
;
1189 MSSTYLES_CloseThemeFile(pt
);
1193 /**********************************************************************
1194 * ParseThemeIniFile (UXTHEME.11)
1196 * Enumerate data in a theme INI file.
1199 * pszIniFileName Path to a theme ini file
1200 * pszUnknown Cannot be NULL, L"" is valid
1201 * callback Called for each found entry
1202 * lpData Passed through to callback
1206 * 0x800706488 (Unknown property) when enumeration is canceled from callback
1209 * When pszUnknown is NULL the callback is never called, the value does not seem to serve
1212 HRESULT WINAPI
ParseThemeIniFile(LPCWSTR pszIniFileName
, LPWSTR pszUnknown
,
1213 ParseThemeIniFileProc callback
, LPVOID lpData
)
1215 FIXME("%s %s: stub\n", debugstr_w(pszIniFileName
), debugstr_w(pszUnknown
));
1219 /**********************************************************************
1220 * CheckThemeSignature (UXTHEME.29)
1222 * Validates the signature of a theme file
1225 * pszIniFileName Path to a theme file
1229 * Failure: HRESULT error-code
1231 HRESULT WINAPI
CheckThemeSignature(LPCWSTR pszThemeFileName
)
1235 TRACE("(%s)\n", debugstr_w(pszThemeFileName
));
1236 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, NULL
, &pt
);
1239 MSSTYLES_CloseThemeFile(pt
);
1243 BOOL WINAPI
ThemeHooksInstall(void)
1245 struct user_api_hook hooks
;
1247 hooks
.pDefDlgProc
= UXTHEME_DefDlgProc
;
1248 hooks
.pNonClientButtonDraw
= UXTHEME_NonClientButtonDraw
;
1249 hooks
.pScrollBarDraw
= UXTHEME_ScrollBarDraw
;
1250 hooks
.pScrollBarWndProc
= UXTHEME_ScrollbarWndProc
;
1251 return RegisterUserApiHook(&hooks
, &user_api
);
1254 BOOL WINAPI
ThemeHooksRemove(void)
1256 UnregisterUserApiHook();