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 /***********************************************************************/
60 static BOOL CALLBACK
UXTHEME_broadcast_msg_enumchild (HWND hWnd
, LPARAM msg
)
62 PostMessageW(hWnd
, msg
, 0, 0);
66 /* Broadcast a message to *all* windows, including children */
67 static BOOL CALLBACK
UXTHEME_broadcast_msg (HWND hWnd
, LPARAM msg
)
71 EnumWindows (UXTHEME_broadcast_msg
, msg
);
75 PostMessageW(hWnd
, msg
, 0, 0);
76 EnumChildWindows (hWnd
, UXTHEME_broadcast_msg_enumchild
, msg
);
81 /* At the end of the day this is a subset of what SHRegGetPath() does - copied
82 * here to avoid linking against shlwapi. */
83 static DWORD
query_reg_path (HKEY hKey
, LPCWSTR lpszValue
,
86 DWORD dwRet
, dwType
, dwUnExpDataLen
= MAX_PATH
, dwExpDataLen
;
88 TRACE("(hkey=%p,%s,%p)\n", hKey
, debugstr_w(lpszValue
),
91 dwRet
= RegQueryValueExW(hKey
, lpszValue
, 0, &dwType
, pvData
, &dwUnExpDataLen
);
92 if (dwRet
!=ERROR_SUCCESS
&& dwRet
!=ERROR_MORE_DATA
)
95 if (dwType
== REG_EXPAND_SZ
)
99 /* Expand type REG_EXPAND_SZ into REG_SZ */
102 /* If the caller didn't supply a buffer or the buffer is too small we have
103 * to allocate our own
105 if (dwRet
== ERROR_MORE_DATA
)
107 WCHAR emptyW
[] = L
"";
108 nBytesToAlloc
= dwUnExpDataLen
;
110 szData
= LocalAlloc(LMEM_ZEROINIT
, nBytesToAlloc
);
111 RegQueryValueExW (hKey
, lpszValue
, 0, NULL
, (LPBYTE
)szData
, &nBytesToAlloc
);
112 dwExpDataLen
= ExpandEnvironmentStringsW(szData
, emptyW
, 1);
113 dwUnExpDataLen
= max(nBytesToAlloc
, dwExpDataLen
);
118 nBytesToAlloc
= (lstrlenW(pvData
) + 1) * sizeof(WCHAR
);
119 szData
= LocalAlloc(LMEM_ZEROINIT
, nBytesToAlloc
);
120 lstrcpyW(szData
, pvData
);
121 dwExpDataLen
= ExpandEnvironmentStringsW(szData
, pvData
, MAX_PATH
);
122 if (dwExpDataLen
> MAX_PATH
) dwRet
= ERROR_MORE_DATA
;
123 dwUnExpDataLen
= max(nBytesToAlloc
, dwExpDataLen
);
132 /***********************************************************************
135 * Set the current active theme from the registry
137 static void UXTHEME_LoadTheme(void)
145 /* Get current theme configuration */
146 if(!RegOpenKeyW(HKEY_CURRENT_USER
, szThemeManager
, &hKey
)) {
147 TRACE("Loading theme config\n");
148 buffsize
= ARRAY_SIZE(tmp
);
149 if (!RegQueryValueExW(hKey
, L
"ThemeActive", NULL
, NULL
, (BYTE
*)tmp
, &buffsize
)) {
150 bThemeActive
= (tmp
[0] != '0');
153 bThemeActive
= FALSE
;
154 TRACE("Failed to get ThemeActive: %d\n", GetLastError());
156 buffsize
= ARRAY_SIZE(szCurrentColor
);
157 if (RegQueryValueExW(hKey
, L
"ColorName", NULL
, NULL
, (BYTE
*)szCurrentColor
, &buffsize
))
158 szCurrentColor
[0] = '\0';
159 buffsize
= ARRAY_SIZE(szCurrentSize
);
160 if (RegQueryValueExW(hKey
, L
"SizeName", NULL
, NULL
, (BYTE
*)szCurrentSize
, &buffsize
))
161 szCurrentSize
[0] = '\0';
162 if (query_reg_path (hKey
, L
"DllName", szCurrentTheme
))
163 szCurrentTheme
[0] = '\0';
167 TRACE("Failed to open theme registry key\n");
170 /* Make sure the theme requested is actually valid */
171 hr
= MSSTYLES_OpenThemeFile(szCurrentTheme
,
172 szCurrentColor
[0]?szCurrentColor
:NULL
,
173 szCurrentSize
[0]?szCurrentSize
:NULL
,
176 bThemeActive
= FALSE
;
177 szCurrentTheme
[0] = '\0';
178 szCurrentColor
[0] = '\0';
179 szCurrentSize
[0] = '\0';
182 /* Make sure the global color & size match the theme */
183 lstrcpynW(szCurrentColor
, pt
->pszSelectedColor
, ARRAY_SIZE(szCurrentColor
));
184 lstrcpynW(szCurrentSize
, pt
->pszSelectedSize
, ARRAY_SIZE(szCurrentSize
));
186 MSSTYLES_SetActiveTheme(pt
, FALSE
);
187 TRACE("Theme active: %s %s %s\n", debugstr_w(szCurrentTheme
),
188 debugstr_w(szCurrentColor
), debugstr_w(szCurrentSize
));
189 MSSTYLES_CloseThemeFile(pt
);
193 MSSTYLES_SetActiveTheme(NULL
, FALSE
);
194 TRACE("Theming not active\n");
198 /***********************************************************************/
200 static const char * const SysColorsNames
[] =
202 "Scrollbar", /* COLOR_SCROLLBAR */
203 "Background", /* COLOR_BACKGROUND */
204 "ActiveTitle", /* COLOR_ACTIVECAPTION */
205 "InactiveTitle", /* COLOR_INACTIVECAPTION */
206 "Menu", /* COLOR_MENU */
207 "Window", /* COLOR_WINDOW */
208 "WindowFrame", /* COLOR_WINDOWFRAME */
209 "MenuText", /* COLOR_MENUTEXT */
210 "WindowText", /* COLOR_WINDOWTEXT */
211 "TitleText", /* COLOR_CAPTIONTEXT */
212 "ActiveBorder", /* COLOR_ACTIVEBORDER */
213 "InactiveBorder", /* COLOR_INACTIVEBORDER */
214 "AppWorkSpace", /* COLOR_APPWORKSPACE */
215 "Hilight", /* COLOR_HIGHLIGHT */
216 "HilightText", /* COLOR_HIGHLIGHTTEXT */
217 "ButtonFace", /* COLOR_BTNFACE */
218 "ButtonShadow", /* COLOR_BTNSHADOW */
219 "GrayText", /* COLOR_GRAYTEXT */
220 "ButtonText", /* COLOR_BTNTEXT */
221 "InactiveTitleText", /* COLOR_INACTIVECAPTIONTEXT */
222 "ButtonHilight", /* COLOR_BTNHIGHLIGHT */
223 "ButtonDkShadow", /* COLOR_3DDKSHADOW */
224 "ButtonLight", /* COLOR_3DLIGHT */
225 "InfoText", /* COLOR_INFOTEXT */
226 "InfoWindow", /* COLOR_INFOBK */
227 "ButtonAlternateFace", /* COLOR_ALTERNATEBTNFACE */
228 "HotTrackingColor", /* COLOR_HOTLIGHT */
229 "GradientActiveTitle", /* COLOR_GRADIENTACTIVECAPTION */
230 "GradientInactiveTitle", /* COLOR_GRADIENTINACTIVECAPTION */
231 "MenuHilight", /* COLOR_MENUHILIGHT */
232 "MenuBar", /* COLOR_MENUBAR */
235 static const WCHAR strColorKey
[] = L
"Control Panel\\Colors";
237 static const struct BackupSysParam
240 const WCHAR
* keyName
;
241 } backupSysParams
[] =
243 {SPI_GETFLATMENU
, SPI_SETFLATMENU
, L
"FlatMenu"},
244 {SPI_GETGRADIENTCAPTIONS
, SPI_SETGRADIENTCAPTIONS
, L
"GradientCaption"},
248 #define NUM_SYS_COLORS (COLOR_MENUBAR+1)
250 static void save_sys_colors (HKEY baseKey
)
256 if (RegCreateKeyExW( baseKey
, strColorKey
,
257 0, 0, 0, KEY_ALL_ACCESS
,
258 0, &hKey
, 0 ) == ERROR_SUCCESS
)
260 for (i
= 0; i
< NUM_SYS_COLORS
; i
++)
262 COLORREF col
= GetSysColor (i
);
264 sprintf (colorStr
, "%d %d %d",
265 GetRValue (col
), GetGValue (col
), GetBValue (col
));
267 RegSetValueExA (hKey
, SysColorsNames
[i
], 0, REG_SZ
,
268 (BYTE
*)colorStr
, strlen (colorStr
)+1);
274 /* Before activating a theme, query current system colors, certain settings
275 * and backup them in the registry, so they can be restored when the theme
277 static void UXTHEME_BackupSystemMetrics(void)
280 const struct BackupSysParam
* bsp
= backupSysParams
;
282 if (RegCreateKeyExW( HKEY_CURRENT_USER
, szThemeManager
,
283 0, 0, 0, KEY_ALL_ACCESS
,
284 0, &hKey
, 0) == ERROR_SUCCESS
)
286 NONCLIENTMETRICSW ncm
;
287 LOGFONTW iconTitleFont
;
290 save_sys_colors (hKey
);
292 /* back up "other" settings */
293 while (bsp
->spiGet
>= 0)
297 SystemParametersInfoW (bsp
->spiGet
, 0, &value
, 0);
298 RegSetValueExW (hKey
, bsp
->keyName
, 0, REG_DWORD
,
299 (LPBYTE
)&value
, sizeof (value
));
304 /* back up non-client metrics */
305 memset (&ncm
, 0, sizeof (ncm
));
306 ncm
.cbSize
= sizeof (ncm
);
307 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof (ncm
), &ncm
, 0);
308 RegSetValueExW (hKey
, L
"NonClientMetrics", 0, REG_BINARY
, (BYTE
*)&ncm
,
310 memset (&iconTitleFont
, 0, sizeof (iconTitleFont
));
311 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, sizeof (iconTitleFont
),
313 RegSetValueExW (hKey
, L
"IconTitleFont", 0, REG_BINARY
,
314 (LPBYTE
)&iconTitleFont
, sizeof (iconTitleFont
));
320 /* Read back old settings after a theme was deactivated */
321 static void UXTHEME_RestoreSystemMetrics(void)
324 const struct BackupSysParam
* bsp
= backupSysParams
;
326 if (RegOpenKeyExW (HKEY_CURRENT_USER
, szThemeManager
,
327 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
)
331 /* read backed-up colors */
332 if (RegOpenKeyExW (hKey
, strColorKey
,
333 0, KEY_QUERY_VALUE
, &colorKey
) == ERROR_SUCCESS
)
336 COLORREF sysCols
[NUM_SYS_COLORS
];
337 int sysColsIndices
[NUM_SYS_COLORS
];
340 for (i
= 0; i
< NUM_SYS_COLORS
; i
++)
344 DWORD count
= sizeof(colorStr
);
346 if (RegQueryValueExA (colorKey
, SysColorsNames
[i
], 0,
347 &type
, (LPBYTE
) colorStr
, &count
) == ERROR_SUCCESS
)
350 if (sscanf (colorStr
, "%d %d %d", &r
, &g
, &b
) == 3)
352 sysColsIndices
[sysColCount
] = i
;
353 sysCols
[sysColCount
] = RGB(r
, g
, b
);
358 RegCloseKey (colorKey
);
360 SetSysColors (sysColCount
, sysColsIndices
, sysCols
);
363 /* read backed-up other settings */
364 while (bsp
->spiGet
>= 0)
367 DWORD count
= sizeof(value
);
370 if (RegQueryValueExW (hKey
, bsp
->keyName
, 0,
371 &type
, (LPBYTE
)&value
, &count
) == ERROR_SUCCESS
)
373 SystemParametersInfoW (bsp
->spiSet
, 0, UlongToPtr(value
), SPIF_UPDATEINIFILE
);
379 /* read backed-up non-client metrics */
381 NONCLIENTMETRICSW ncm
;
382 LOGFONTW iconTitleFont
;
383 DWORD count
= sizeof(ncm
);
386 if (RegQueryValueExW (hKey
, L
"NonClientMetrics", 0,
387 &type
, (LPBYTE
)&ncm
, &count
) == ERROR_SUCCESS
)
389 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS
,
390 count
, &ncm
, SPIF_UPDATEINIFILE
);
393 count
= sizeof(iconTitleFont
);
395 if (RegQueryValueExW (hKey
, L
"IconTitleFont", 0,
396 &type
, (LPBYTE
)&iconTitleFont
, &count
) == ERROR_SUCCESS
)
398 SystemParametersInfoW (SPI_SETICONTITLELOGFONT
,
399 count
, &iconTitleFont
, SPIF_UPDATEINIFILE
);
407 /* Make system settings persistent, so they're in effect even w/o uxtheme
409 * For efficiency reasons, only the last SystemParametersInfoW sets
410 * SPIF_SENDWININICHANGE */
411 static void UXTHEME_SaveSystemMetrics(void)
413 const struct BackupSysParam
* bsp
= backupSysParams
;
414 NONCLIENTMETRICSW ncm
;
415 LOGFONTW iconTitleFont
;
417 save_sys_colors (HKEY_CURRENT_USER
);
419 while (bsp
->spiGet
>= 0)
423 SystemParametersInfoW (bsp
->spiGet
, 0, &value
, 0);
424 SystemParametersInfoW (bsp
->spiSet
, 0, UlongToPtr(value
), SPIF_UPDATEINIFILE
);
428 memset (&ncm
, 0, sizeof (ncm
));
429 ncm
.cbSize
= sizeof (ncm
);
430 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof (ncm
), &ncm
, 0);
431 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS
, sizeof (ncm
), &ncm
,
434 memset (&iconTitleFont
, 0, sizeof (iconTitleFont
));
435 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, sizeof (iconTitleFont
),
437 SystemParametersInfoW (SPI_SETICONTITLELOGFONT
, sizeof (iconTitleFont
),
438 &iconTitleFont
, SPIF_UPDATEINIFILE
| SPIF_SENDCHANGE
);
441 /***********************************************************************
442 * UXTHEME_SetActiveTheme
444 * Change the current active theme
446 static HRESULT
UXTHEME_SetActiveTheme(PTHEME_FILE tf
)
452 if(tf
&& !bThemeActive
) UXTHEME_BackupSystemMetrics();
453 hr
= MSSTYLES_SetActiveTheme(tf
, TRUE
);
458 lstrcpynW(szCurrentTheme
, tf
->szThemeFile
, ARRAY_SIZE(szCurrentTheme
));
459 lstrcpynW(szCurrentColor
, tf
->pszSelectedColor
, ARRAY_SIZE(szCurrentColor
));
460 lstrcpynW(szCurrentSize
, tf
->pszSelectedSize
, ARRAY_SIZE(szCurrentSize
));
463 UXTHEME_RestoreSystemMetrics();
464 bThemeActive
= FALSE
;
465 szCurrentTheme
[0] = '\0';
466 szCurrentColor
[0] = '\0';
467 szCurrentSize
[0] = '\0';
470 TRACE("Writing theme config to registry\n");
471 if(!RegCreateKeyW(HKEY_CURRENT_USER
, szThemeManager
, &hKey
)) {
472 tmp
[0] = bThemeActive
?'1':'0';
474 RegSetValueExW(hKey
, L
"ThemeActive", 0, REG_SZ
, (const BYTE
*)tmp
, sizeof(WCHAR
)*2);
476 RegSetValueExW(hKey
, L
"ColorName", 0, REG_SZ
, (const BYTE
*)szCurrentColor
,
477 (lstrlenW(szCurrentColor
)+1)*sizeof(WCHAR
));
478 RegSetValueExW(hKey
, L
"SizeName", 0, REG_SZ
, (const BYTE
*)szCurrentSize
,
479 (lstrlenW(szCurrentSize
)+1)*sizeof(WCHAR
));
480 RegSetValueExW(hKey
, L
"DllName", 0, REG_SZ
, (const BYTE
*)szCurrentTheme
,
481 (lstrlenW(szCurrentTheme
)+1)*sizeof(WCHAR
));
484 RegDeleteValueW(hKey
, L
"ColorName");
485 RegDeleteValueW(hKey
, L
"SizeName");
486 RegDeleteValueW(hKey
, L
"DllName");
492 TRACE("Failed to open theme registry key\n");
494 UXTHEME_SaveSystemMetrics ();
499 /***********************************************************************
502 void UXTHEME_InitSystem(HINSTANCE hInst
)
504 atWindowTheme
= GlobalAddAtomW(L
"ux_theme");
505 atSubAppName
= GlobalAddAtomW(L
"ux_subapp");
506 atSubIdList
= GlobalAddAtomW(L
"ux_subidlst");
507 atDialogThemeEnabled
= GlobalAddAtomW(L
"ux_dialogtheme");
512 /***********************************************************************
513 * IsAppThemed (UXTHEME.@)
515 BOOL WINAPI
IsAppThemed(void)
517 return IsThemeActive();
520 /***********************************************************************
521 * IsThemeActive (UXTHEME.@)
523 BOOL WINAPI
IsThemeActive(void)
526 SetLastError(ERROR_SUCCESS
);
530 /************************************************************
531 * IsCompositionActive (UXTHEME.@)
533 BOOL WINAPI
IsCompositionActive(void)
537 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
542 /***********************************************************************
543 * EnableTheming (UXTHEME.@)
546 * This is a global and persistent change
548 HRESULT WINAPI
EnableTheming(BOOL fEnable
)
551 WCHAR szEnabled
[] = L
"0";
553 TRACE("(%d)\n", fEnable
);
555 if(fEnable
!= bThemeActive
) {
557 UXTHEME_BackupSystemMetrics();
559 UXTHEME_RestoreSystemMetrics();
560 UXTHEME_SaveSystemMetrics ();
561 bThemeActive
= fEnable
;
562 if(bThemeActive
) szEnabled
[0] = '1';
563 if(!RegOpenKeyW(HKEY_CURRENT_USER
, szThemeManager
, &hKey
)) {
564 RegSetValueExW(hKey
, L
"ThemeActive", 0, REG_SZ
, (BYTE
*)szEnabled
, sizeof(WCHAR
));
567 UXTHEME_broadcast_msg (NULL
, WM_THEMECHANGED
);
572 /***********************************************************************
573 * UXTHEME_SetWindowProperty
575 * I'm using atoms as there may be large numbers of duplicated strings
576 * and they do the work of keeping memory down as a cause of that quite nicely
578 static HRESULT
UXTHEME_SetWindowProperty(HWND hwnd
, ATOM aProp
, LPCWSTR pszValue
)
580 ATOM oldValue
= (ATOM
)(size_t)RemovePropW(hwnd
, (LPCWSTR
)MAKEINTATOM(aProp
));
582 DeleteAtom(oldValue
);
584 ATOM atValue
= AddAtomW(pszValue
);
586 || !SetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(aProp
), (LPWSTR
)MAKEINTATOM(atValue
))) {
587 HRESULT hr
= HRESULT_FROM_WIN32(GetLastError());
588 if(atValue
) DeleteAtom(atValue
);
595 static LPWSTR
UXTHEME_GetWindowProperty(HWND hwnd
, ATOM aProp
, LPWSTR pszBuffer
, int dwLen
)
597 ATOM atValue
= (ATOM
)(size_t)GetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(aProp
));
599 if(GetAtomNameW(atValue
, pszBuffer
, dwLen
))
601 TRACE("property defined, but unable to get value\n");
606 /***********************************************************************
607 * OpenThemeDataEx (UXTHEME.61)
609 HTHEME WINAPI
OpenThemeDataEx(HWND hwnd
, LPCWSTR pszClassList
, DWORD flags
)
611 WCHAR szAppBuff
[256];
612 WCHAR szClassBuff
[256];
614 LPCWSTR pszUseClassList
;
615 HTHEME hTheme
= NULL
;
616 TRACE("(%p,%s, %x)\n", hwnd
, debugstr_w(pszClassList
), flags
);
620 SetLastError(E_POINTER
);
625 FIXME("unhandled flags: %x\n", flags
);
629 pszAppName
= UXTHEME_GetWindowProperty(hwnd
, atSubAppName
, szAppBuff
, ARRAY_SIZE(szAppBuff
));
630 /* If SetWindowTheme was used on the window, that overrides the class list passed to this function */
631 pszUseClassList
= UXTHEME_GetWindowProperty(hwnd
, atSubIdList
, szClassBuff
, ARRAY_SIZE(szClassBuff
));
633 pszUseClassList
= pszClassList
;
636 hTheme
= MSSTYLES_OpenThemeClass(pszAppName
, pszUseClassList
);
639 SetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(atWindowTheme
), hTheme
);
640 TRACE(" = %p\n", hTheme
);
644 /***********************************************************************
645 * OpenThemeData (UXTHEME.@)
647 HTHEME WINAPI
OpenThemeData(HWND hwnd
, LPCWSTR classlist
)
649 return OpenThemeDataEx(hwnd
, classlist
, 0);
652 /***********************************************************************
653 * GetWindowTheme (UXTHEME.@)
655 * Retrieve the last theme opened for a window.
658 * hwnd [I] window to retrieve the theme for
661 * The most recent theme.
663 HTHEME WINAPI
GetWindowTheme(HWND hwnd
)
665 TRACE("(%p)\n", hwnd
);
666 return GetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(atWindowTheme
));
669 /***********************************************************************
670 * SetWindowTheme (UXTHEME.@)
672 * Persistent through the life of the window, even after themes change
674 HRESULT WINAPI
SetWindowTheme(HWND hwnd
, LPCWSTR pszSubAppName
,
675 LPCWSTR pszSubIdList
)
678 TRACE("(%p,%s,%s)\n", hwnd
, debugstr_w(pszSubAppName
),
679 debugstr_w(pszSubIdList
));
680 hr
= UXTHEME_SetWindowProperty(hwnd
, atSubAppName
, pszSubAppName
);
682 hr
= UXTHEME_SetWindowProperty(hwnd
, atSubIdList
, pszSubIdList
);
684 UXTHEME_broadcast_msg (hwnd
, WM_THEMECHANGED
);
688 /***********************************************************************
689 * SetWindowThemeAttribute (UXTHEME.@)
691 HRESULT WINAPI
SetWindowThemeAttribute(HWND hwnd
, enum WINDOWTHEMEATTRIBUTETYPE type
,
692 PVOID attribute
, DWORD size
)
694 FIXME("(%p,%d,%p,%d): stub\n", hwnd
, type
, attribute
, size
);
698 /***********************************************************************
699 * GetCurrentThemeName (UXTHEME.@)
701 HRESULT WINAPI
GetCurrentThemeName(LPWSTR pszThemeFileName
, int dwMaxNameChars
,
702 LPWSTR pszColorBuff
, int cchMaxColorChars
,
703 LPWSTR pszSizeBuff
, int cchMaxSizeChars
)
706 return E_PROP_ID_UNSUPPORTED
;
707 if(pszThemeFileName
) lstrcpynW(pszThemeFileName
, szCurrentTheme
, dwMaxNameChars
);
708 if(pszColorBuff
) lstrcpynW(pszColorBuff
, szCurrentColor
, cchMaxColorChars
);
709 if(pszSizeBuff
) lstrcpynW(pszSizeBuff
, szCurrentSize
, cchMaxSizeChars
);
713 /***********************************************************************
714 * GetThemeAppProperties (UXTHEME.@)
716 DWORD WINAPI
GetThemeAppProperties(void)
718 return dwThemeAppProperties
;
721 /***********************************************************************
722 * SetThemeAppProperties (UXTHEME.@)
724 void WINAPI
SetThemeAppProperties(DWORD dwFlags
)
726 TRACE("(0x%08x)\n", dwFlags
);
727 dwThemeAppProperties
= dwFlags
;
730 /***********************************************************************
731 * CloseThemeData (UXTHEME.@)
733 HRESULT WINAPI
CloseThemeData(HTHEME hTheme
)
735 TRACE("(%p)\n", hTheme
);
736 if(!hTheme
|| hTheme
== INVALID_HANDLE_VALUE
)
738 return MSSTYLES_CloseThemeClass(hTheme
);
741 /***********************************************************************
742 * HitTestThemeBackground (UXTHEME.@)
744 HRESULT WINAPI
HitTestThemeBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
745 int iStateId
, DWORD dwOptions
,
746 const RECT
*pRect
, HRGN hrgn
,
747 POINT ptTest
, WORD
*pwHitTestCode
)
749 FIXME("%d %d 0x%08x: stub\n", iPartId
, iStateId
, dwOptions
);
755 /***********************************************************************
756 * IsThemePartDefined (UXTHEME.@)
758 BOOL WINAPI
IsThemePartDefined(HTHEME hTheme
, int iPartId
, int iStateId
)
760 TRACE("(%p,%d,%d)\n", hTheme
, iPartId
, iStateId
);
762 SetLastError(E_HANDLE
);
765 if(MSSTYLES_FindPartState(hTheme
, iPartId
, iStateId
, NULL
))
770 /***********************************************************************
771 * GetThemeDocumentationProperty (UXTHEME.@)
773 * Try and retrieve the documentation property from string resources
774 * if that fails, get it from the [documentation] section of themes.ini
776 HRESULT WINAPI
GetThemeDocumentationProperty(LPCWSTR pszThemeName
,
777 LPCWSTR pszPropertyName
,
781 static const WORD wDocToRes
[] = {
782 TMT_DISPLAYNAME
,5000,
796 TRACE("(%s,%s,%p,%d)\n", debugstr_w(pszThemeName
), debugstr_w(pszPropertyName
),
797 pszValueBuff
, cchMaxValChars
);
799 hr
= MSSTYLES_OpenThemeFile(pszThemeName
, NULL
, NULL
, &pt
);
800 if(FAILED(hr
)) return hr
;
802 /* Try to load from string resources */
803 hr
= E_PROP_ID_UNSUPPORTED
;
804 if(MSSTYLES_LookupProperty(pszPropertyName
, NULL
, &iDocId
)) {
805 for(i
=0; i
<ARRAY_SIZE(wDocToRes
); i
+=2) {
806 if(wDocToRes
[i
] == iDocId
) {
807 if(LoadStringW(pt
->hTheme
, wDocToRes
[i
+1], pszValueBuff
, cchMaxValChars
)) {
814 /* If loading from string resource failed, try getting it from the theme.ini */
816 PUXINI_FILE uf
= MSSTYLES_GetThemeIni(pt
);
817 if(UXINI_FindSection(uf
, L
"documentation")) {
820 if(UXINI_FindValue(uf
, pszPropertyName
, &lpValue
, &dwLen
)) {
821 lstrcpynW(pszValueBuff
, lpValue
, min(dwLen
+1,cchMaxValChars
));
828 MSSTYLES_CloseThemeFile(pt
);
832 /**********************************************************************
833 * Undocumented functions
836 /**********************************************************************
837 * QueryThemeServices (UXTHEME.1)
840 * some kind of status flag
842 DWORD WINAPI
QueryThemeServices(void)
845 return 3; /* This is what is returned under XP in most cases */
849 /**********************************************************************
850 * OpenThemeFile (UXTHEME.2)
852 * Opens a theme file, which can be used to change the current theme, etc
855 * pszThemeFileName Path to a msstyles theme file
856 * pszColorName Color defined in the theme, eg. NormalColor
857 * pszSizeName Size defined in the theme, eg. NormalSize
858 * hThemeFile Handle to theme file
862 * Failure: HRESULT error-code
864 HRESULT WINAPI
OpenThemeFile(LPCWSTR pszThemeFileName
, LPCWSTR pszColorName
,
865 LPCWSTR pszSizeName
, HTHEMEFILE
*hThemeFile
,
868 TRACE("(%s,%s,%s,%p,%d)\n", debugstr_w(pszThemeFileName
),
869 debugstr_w(pszColorName
), debugstr_w(pszSizeName
),
870 hThemeFile
, unknown
);
871 return MSSTYLES_OpenThemeFile(pszThemeFileName
, pszColorName
, pszSizeName
, (PTHEME_FILE
*)hThemeFile
);
874 /**********************************************************************
875 * CloseThemeFile (UXTHEME.3)
877 * Releases theme file handle returned by OpenThemeFile
880 * hThemeFile Handle to theme file
884 * Failure: HRESULT error-code
886 HRESULT WINAPI
CloseThemeFile(HTHEMEFILE hThemeFile
)
888 TRACE("(%p)\n", hThemeFile
);
889 MSSTYLES_CloseThemeFile(hThemeFile
);
893 /**********************************************************************
894 * ApplyTheme (UXTHEME.4)
896 * Set a theme file to be the currently active theme
899 * hThemeFile Handle to theme file
901 * hWnd Window requesting the theme change
905 * Failure: HRESULT error-code
908 * I'm not sure what the second parameter is (the datatype is likely wrong), other then this:
911 * the theme is applied with the screen redrawing really badly (flickers)
912 * char b[] = "\0"; where \0 can be one or more of any character, makes no difference
913 * the theme is applied smoothly (screen does not flicker)
914 * char *b = "\0" or NULL; where \0 can be zero or more of any character, makes no difference
915 * the function fails returning invalid parameter... very strange
917 HRESULT WINAPI
ApplyTheme(HTHEMEFILE hThemeFile
, char *unknown
, HWND hWnd
)
920 TRACE("(%p,%s,%p)\n", hThemeFile
, unknown
, hWnd
);
921 hr
= UXTHEME_SetActiveTheme(hThemeFile
);
922 UXTHEME_broadcast_msg (NULL
, WM_THEMECHANGED
);
926 /**********************************************************************
927 * GetThemeDefaults (UXTHEME.7)
929 * Get the default color & size for a theme
932 * pszThemeFileName Path to a msstyles theme file
933 * pszColorName Buffer to receive the default color name
934 * dwColorNameLen Length, in characters, of color name buffer
935 * pszSizeName Buffer to receive the default size name
936 * dwSizeNameLen Length, in characters, of size name buffer
940 * Failure: HRESULT error-code
942 HRESULT WINAPI
GetThemeDefaults(LPCWSTR pszThemeFileName
, LPWSTR pszColorName
,
943 DWORD dwColorNameLen
, LPWSTR pszSizeName
,
948 TRACE("(%s,%p,%d,%p,%d)\n", debugstr_w(pszThemeFileName
),
949 pszColorName
, dwColorNameLen
,
950 pszSizeName
, dwSizeNameLen
);
952 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, NULL
, &pt
);
953 if(FAILED(hr
)) return hr
;
955 lstrcpynW(pszColorName
, pt
->pszSelectedColor
, dwColorNameLen
);
956 lstrcpynW(pszSizeName
, pt
->pszSelectedSize
, dwSizeNameLen
);
958 MSSTYLES_CloseThemeFile(pt
);
962 /**********************************************************************
963 * EnumThemes (UXTHEME.8)
965 * Enumerate available themes, calls specified EnumThemeProc for each
966 * theme found. Passes lpData through to callback function.
969 * pszThemePath Path containing themes
970 * callback Called for each theme found in path
971 * lpData Passed through to callback
975 * Failure: HRESULT error-code
977 HRESULT WINAPI
EnumThemes(LPCWSTR pszThemePath
, EnumThemeProc callback
,
980 WCHAR szDir
[MAX_PATH
];
981 WCHAR szPath
[MAX_PATH
];
985 WIN32_FIND_DATAW wfd
;
989 TRACE("(%s,%p,%p)\n", debugstr_w(pszThemePath
), callback
, lpData
);
991 if(!pszThemePath
|| !callback
)
994 lstrcpyW(szDir
, pszThemePath
);
995 pathLen
= lstrlenW (szDir
);
996 if ((pathLen
> 0) && (pathLen
< MAX_PATH
-1) && (szDir
[pathLen
- 1] != '\\'))
998 szDir
[pathLen
] = '\\';
999 szDir
[pathLen
+1] = 0;
1002 lstrcpyW(szPath
, szDir
);
1003 lstrcatW(szPath
, L
"*.*");
1004 TRACE("searching %s\n", debugstr_w(szPath
));
1006 hFind
= FindFirstFileW(szPath
, &wfd
);
1007 if(hFind
!= INVALID_HANDLE_VALUE
) {
1009 if(wfd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
1010 && !(wfd
.cFileName
[0] == '.' && ((wfd
.cFileName
[1] == '.' && wfd
.cFileName
[2] == 0) || wfd
.cFileName
[1] == 0))) {
1011 wsprintfW(szPath
, L
"%s%s\\%s.msstyles", szDir
, wfd
.cFileName
, wfd
.cFileName
);
1013 hr
= GetThemeDocumentationProperty(szPath
, L
"displayname", szName
, ARRAY_SIZE(szName
));
1015 hr
= GetThemeDocumentationProperty(szPath
, L
"tooltip", szTip
, ARRAY_SIZE(szTip
));
1017 TRACE("callback(%s,%s,%s,%p)\n", debugstr_w(szPath
), debugstr_w(szName
), debugstr_w(szTip
), lpData
);
1018 if(!callback(NULL
, szPath
, szName
, szTip
, NULL
, lpData
)) {
1019 TRACE("callback ended enum\n");
1024 } while(FindNextFileW(hFind
, &wfd
));
1031 /**********************************************************************
1032 * EnumThemeColors (UXTHEME.9)
1034 * Enumerate theme colors available with a particular size
1037 * pszThemeFileName Path to a msstyles theme file
1038 * pszSizeName Theme size to enumerate available colors
1039 * If NULL the default theme size is used
1040 * dwColorNum Color index to retrieve, increment from 0
1041 * pszColorNames Output color names
1045 * E_PROP_ID_UNSUPPORTED when dwColorName does not refer to a color
1046 * or when pszSizeName does not refer to a valid size
1049 * XP fails with E_POINTER when pszColorNames points to a buffer smaller than
1050 * sizeof(THEMENAMES).
1052 * Not very efficient that I'm opening & validating the theme every call, but
1053 * this is undocumented and almost never called..
1054 * (and this is how windows works too)
1056 HRESULT WINAPI
EnumThemeColors(LPWSTR pszThemeFileName
, LPWSTR pszSizeName
,
1057 DWORD dwColorNum
, PTHEMENAMES pszColorNames
)
1062 UINT resourceId
= dwColorNum
+ 1000;
1063 TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName
),
1064 debugstr_w(pszSizeName
), dwColorNum
);
1066 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, pszSizeName
, &pt
);
1067 if(FAILED(hr
)) return hr
;
1069 tmp
= pt
->pszAvailColors
;
1070 while(dwColorNum
&& *tmp
) {
1072 tmp
+= lstrlenW(tmp
)+1;
1074 if(!dwColorNum
&& *tmp
) {
1075 TRACE("%s\n", debugstr_w(tmp
));
1076 lstrcpyW(pszColorNames
->szName
, tmp
);
1077 LoadStringW(pt
->hTheme
, resourceId
, pszColorNames
->szDisplayName
,
1078 ARRAY_SIZE(pszColorNames
->szDisplayName
));
1079 LoadStringW(pt
->hTheme
, resourceId
+1000, pszColorNames
->szTooltip
,
1080 ARRAY_SIZE(pszColorNames
->szTooltip
));
1083 hr
= E_PROP_ID_UNSUPPORTED
;
1085 MSSTYLES_CloseThemeFile(pt
);
1089 /**********************************************************************
1090 * EnumThemeSizes (UXTHEME.10)
1092 * Enumerate theme colors available with a particular size
1095 * pszThemeFileName Path to a msstyles theme file
1096 * pszColorName Theme color to enumerate available sizes
1097 * If NULL the default theme color is used
1098 * dwSizeNum Size index to retrieve, increment from 0
1099 * pszSizeNames Output size names
1103 * E_PROP_ID_UNSUPPORTED when dwSizeName does not refer to a size
1104 * or when pszColorName does not refer to a valid color
1107 * XP fails with E_POINTER when pszSizeNames points to a buffer smaller than
1108 * sizeof(THEMENAMES).
1110 * Not very efficient that I'm opening & validating the theme every call, but
1111 * this is undocumented and almost never called..
1112 * (and this is how windows works too)
1114 HRESULT WINAPI
EnumThemeSizes(LPWSTR pszThemeFileName
, LPWSTR pszColorName
,
1115 DWORD dwSizeNum
, PTHEMENAMES pszSizeNames
)
1120 UINT resourceId
= dwSizeNum
+ 3000;
1121 TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName
),
1122 debugstr_w(pszColorName
), dwSizeNum
);
1124 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, pszColorName
, NULL
, &pt
);
1125 if(FAILED(hr
)) return hr
;
1127 tmp
= pt
->pszAvailSizes
;
1128 while(dwSizeNum
&& *tmp
) {
1130 tmp
+= lstrlenW(tmp
)+1;
1132 if(!dwSizeNum
&& *tmp
) {
1133 TRACE("%s\n", debugstr_w(tmp
));
1134 lstrcpyW(pszSizeNames
->szName
, tmp
);
1135 LoadStringW(pt
->hTheme
, resourceId
, pszSizeNames
->szDisplayName
,
1136 ARRAY_SIZE(pszSizeNames
->szDisplayName
));
1137 LoadStringW(pt
->hTheme
, resourceId
+1000, pszSizeNames
->szTooltip
,
1138 ARRAY_SIZE(pszSizeNames
->szTooltip
));
1141 hr
= E_PROP_ID_UNSUPPORTED
;
1143 MSSTYLES_CloseThemeFile(pt
);
1147 /**********************************************************************
1148 * ParseThemeIniFile (UXTHEME.11)
1150 * Enumerate data in a theme INI file.
1153 * pszIniFileName Path to a theme ini file
1154 * pszUnknown Cannot be NULL, L"" is valid
1155 * callback Called for each found entry
1156 * lpData Passed through to callback
1160 * 0x800706488 (Unknown property) when enumeration is canceled from callback
1163 * When pszUnknown is NULL the callback is never called, the value does not seem to serve
1166 HRESULT WINAPI
ParseThemeIniFile(LPCWSTR pszIniFileName
, LPWSTR pszUnknown
,
1167 ParseThemeIniFileProc callback
, LPVOID lpData
)
1169 FIXME("%s %s: stub\n", debugstr_w(pszIniFileName
), debugstr_w(pszUnknown
));
1173 /**********************************************************************
1174 * CheckThemeSignature (UXTHEME.29)
1176 * Validates the signature of a theme file
1179 * pszIniFileName Path to a theme file
1183 * Failure: HRESULT error-code
1185 HRESULT WINAPI
CheckThemeSignature(LPCWSTR pszThemeFileName
)
1189 TRACE("(%s)\n", debugstr_w(pszThemeFileName
));
1190 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, NULL
, &pt
);
1193 MSSTYLES_CloseThemeFile(pt
);