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
, 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
= ARRAY_SIZE(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: %d\n", GetLastError());
158 buffsize
= ARRAY_SIZE(szCurrentColor
);
159 if (RegQueryValueExW(hKey
, L
"ColorName", NULL
, NULL
, (BYTE
*)szCurrentColor
, &buffsize
))
160 szCurrentColor
[0] = '\0';
161 buffsize
= ARRAY_SIZE(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 MSSTYLES_SetActiveTheme(pt
, FALSE
);
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 char * const SysColorsNames
[] =
204 "Scrollbar", /* COLOR_SCROLLBAR */
205 "Background", /* COLOR_BACKGROUND */
206 "ActiveTitle", /* COLOR_ACTIVECAPTION */
207 "InactiveTitle", /* COLOR_INACTIVECAPTION */
208 "Menu", /* COLOR_MENU */
209 "Window", /* COLOR_WINDOW */
210 "WindowFrame", /* COLOR_WINDOWFRAME */
211 "MenuText", /* COLOR_MENUTEXT */
212 "WindowText", /* COLOR_WINDOWTEXT */
213 "TitleText", /* COLOR_CAPTIONTEXT */
214 "ActiveBorder", /* COLOR_ACTIVEBORDER */
215 "InactiveBorder", /* COLOR_INACTIVEBORDER */
216 "AppWorkSpace", /* COLOR_APPWORKSPACE */
217 "Hilight", /* COLOR_HIGHLIGHT */
218 "HilightText", /* COLOR_HIGHLIGHTTEXT */
219 "ButtonFace", /* COLOR_BTNFACE */
220 "ButtonShadow", /* COLOR_BTNSHADOW */
221 "GrayText", /* COLOR_GRAYTEXT */
222 "ButtonText", /* COLOR_BTNTEXT */
223 "InactiveTitleText", /* COLOR_INACTIVECAPTIONTEXT */
224 "ButtonHilight", /* COLOR_BTNHIGHLIGHT */
225 "ButtonDkShadow", /* COLOR_3DDKSHADOW */
226 "ButtonLight", /* COLOR_3DLIGHT */
227 "InfoText", /* COLOR_INFOTEXT */
228 "InfoWindow", /* COLOR_INFOBK */
229 "ButtonAlternateFace", /* COLOR_ALTERNATEBTNFACE */
230 "HotTrackingColor", /* COLOR_HOTLIGHT */
231 "GradientActiveTitle", /* COLOR_GRADIENTACTIVECAPTION */
232 "GradientInactiveTitle", /* COLOR_GRADIENTINACTIVECAPTION */
233 "MenuHilight", /* COLOR_MENUHILIGHT */
234 "MenuBar", /* COLOR_MENUBAR */
237 static const WCHAR strColorKey
[] = L
"Control Panel\\Colors";
239 static const struct BackupSysParam
242 const WCHAR
* keyName
;
243 } backupSysParams
[] =
245 {SPI_GETFLATMENU
, SPI_SETFLATMENU
, L
"FlatMenu"},
246 {SPI_GETGRADIENTCAPTIONS
, SPI_SETGRADIENTCAPTIONS
, L
"GradientCaption"},
250 #define NUM_SYS_COLORS (COLOR_MENUBAR+1)
252 static void save_sys_colors (HKEY baseKey
)
258 if (RegCreateKeyExW( baseKey
, strColorKey
,
259 0, 0, 0, KEY_ALL_ACCESS
,
260 0, &hKey
, 0 ) == ERROR_SUCCESS
)
262 for (i
= 0; i
< NUM_SYS_COLORS
; i
++)
264 COLORREF col
= GetSysColor (i
);
266 sprintf (colorStr
, "%d %d %d",
267 GetRValue (col
), GetGValue (col
), GetBValue (col
));
269 RegSetValueExA (hKey
, SysColorsNames
[i
], 0, REG_SZ
,
270 (BYTE
*)colorStr
, strlen (colorStr
)+1);
276 /* Before activating a theme, query current system colors, certain settings
277 * and backup them in the registry, so they can be restored when the theme
279 static void UXTHEME_BackupSystemMetrics(void)
282 const struct BackupSysParam
* bsp
= backupSysParams
;
284 if (RegCreateKeyExW( HKEY_CURRENT_USER
, szThemeManager
,
285 0, 0, 0, KEY_ALL_ACCESS
,
286 0, &hKey
, 0) == ERROR_SUCCESS
)
288 NONCLIENTMETRICSW ncm
;
289 LOGFONTW iconTitleFont
;
292 save_sys_colors (hKey
);
294 /* back up "other" settings */
295 while (bsp
->spiGet
>= 0)
299 SystemParametersInfoW (bsp
->spiGet
, 0, &value
, 0);
300 RegSetValueExW (hKey
, bsp
->keyName
, 0, REG_DWORD
,
301 (LPBYTE
)&value
, sizeof (value
));
306 /* back up non-client metrics */
307 memset (&ncm
, 0, sizeof (ncm
));
308 ncm
.cbSize
= sizeof (ncm
);
309 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof (ncm
), &ncm
, 0);
310 RegSetValueExW (hKey
, L
"NonClientMetrics", 0, REG_BINARY
, (BYTE
*)&ncm
,
312 memset (&iconTitleFont
, 0, sizeof (iconTitleFont
));
313 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, sizeof (iconTitleFont
),
315 RegSetValueExW (hKey
, L
"IconTitleFont", 0, REG_BINARY
,
316 (LPBYTE
)&iconTitleFont
, sizeof (iconTitleFont
));
322 /* Read back old settings after a theme was deactivated */
323 static void UXTHEME_RestoreSystemMetrics(void)
326 const struct BackupSysParam
* bsp
= backupSysParams
;
328 if (RegOpenKeyExW (HKEY_CURRENT_USER
, szThemeManager
,
329 0, KEY_QUERY_VALUE
, &hKey
) == ERROR_SUCCESS
)
333 /* read backed-up colors */
334 if (RegOpenKeyExW (hKey
, strColorKey
,
335 0, KEY_QUERY_VALUE
, &colorKey
) == ERROR_SUCCESS
)
338 COLORREF sysCols
[NUM_SYS_COLORS
];
339 int sysColsIndices
[NUM_SYS_COLORS
];
342 for (i
= 0; i
< NUM_SYS_COLORS
; i
++)
346 DWORD count
= sizeof(colorStr
);
348 if (RegQueryValueExA (colorKey
, SysColorsNames
[i
], 0,
349 &type
, (LPBYTE
) colorStr
, &count
) == ERROR_SUCCESS
)
352 if (sscanf (colorStr
, "%d %d %d", &r
, &g
, &b
) == 3)
354 sysColsIndices
[sysColCount
] = i
;
355 sysCols
[sysColCount
] = RGB(r
, g
, b
);
360 RegCloseKey (colorKey
);
362 SetSysColors (sysColCount
, sysColsIndices
, sysCols
);
365 /* read backed-up other settings */
366 while (bsp
->spiGet
>= 0)
369 DWORD count
= sizeof(value
);
372 if (RegQueryValueExW (hKey
, bsp
->keyName
, 0,
373 &type
, (LPBYTE
)&value
, &count
) == ERROR_SUCCESS
)
375 SystemParametersInfoW (bsp
->spiSet
, 0, UlongToPtr(value
), SPIF_UPDATEINIFILE
);
381 /* read backed-up non-client metrics */
383 NONCLIENTMETRICSW ncm
;
384 LOGFONTW iconTitleFont
;
385 DWORD count
= sizeof(ncm
);
388 if (RegQueryValueExW (hKey
, L
"NonClientMetrics", 0,
389 &type
, (LPBYTE
)&ncm
, &count
) == ERROR_SUCCESS
)
391 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS
,
392 count
, &ncm
, SPIF_UPDATEINIFILE
);
395 count
= sizeof(iconTitleFont
);
397 if (RegQueryValueExW (hKey
, L
"IconTitleFont", 0,
398 &type
, (LPBYTE
)&iconTitleFont
, &count
) == ERROR_SUCCESS
)
400 SystemParametersInfoW (SPI_SETICONTITLELOGFONT
,
401 count
, &iconTitleFont
, SPIF_UPDATEINIFILE
);
409 /* Make system settings persistent, so they're in effect even w/o uxtheme
411 * For efficiency reasons, only the last SystemParametersInfoW sets
412 * SPIF_SENDWININICHANGE */
413 static void UXTHEME_SaveSystemMetrics(void)
415 const struct BackupSysParam
* bsp
= backupSysParams
;
416 NONCLIENTMETRICSW ncm
;
417 LOGFONTW iconTitleFont
;
419 save_sys_colors (HKEY_CURRENT_USER
);
421 while (bsp
->spiGet
>= 0)
425 SystemParametersInfoW (bsp
->spiGet
, 0, &value
, 0);
426 SystemParametersInfoW (bsp
->spiSet
, 0, UlongToPtr(value
), SPIF_UPDATEINIFILE
);
430 memset (&ncm
, 0, sizeof (ncm
));
431 ncm
.cbSize
= sizeof (ncm
);
432 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, sizeof (ncm
), &ncm
, 0);
433 SystemParametersInfoW (SPI_SETNONCLIENTMETRICS
, sizeof (ncm
), &ncm
,
436 memset (&iconTitleFont
, 0, sizeof (iconTitleFont
));
437 SystemParametersInfoW (SPI_GETICONTITLELOGFONT
, sizeof (iconTitleFont
),
439 SystemParametersInfoW (SPI_SETICONTITLELOGFONT
, sizeof (iconTitleFont
),
440 &iconTitleFont
, SPIF_UPDATEINIFILE
| SPIF_SENDCHANGE
);
443 /***********************************************************************
444 * UXTHEME_SetActiveTheme
446 * Change the current active theme
448 static HRESULT
UXTHEME_SetActiveTheme(PTHEME_FILE tf
)
454 if(tf
&& !bThemeActive
) UXTHEME_BackupSystemMetrics();
455 hr
= MSSTYLES_SetActiveTheme(tf
, TRUE
);
460 lstrcpynW(szCurrentTheme
, tf
->szThemeFile
, ARRAY_SIZE(szCurrentTheme
));
461 lstrcpynW(szCurrentColor
, tf
->pszSelectedColor
, ARRAY_SIZE(szCurrentColor
));
462 lstrcpynW(szCurrentSize
, tf
->pszSelectedSize
, ARRAY_SIZE(szCurrentSize
));
465 UXTHEME_RestoreSystemMetrics();
466 bThemeActive
= FALSE
;
467 szCurrentTheme
[0] = '\0';
468 szCurrentColor
[0] = '\0';
469 szCurrentSize
[0] = '\0';
472 TRACE("Writing theme config to registry\n");
473 if(!RegCreateKeyW(HKEY_CURRENT_USER
, szThemeManager
, &hKey
)) {
474 tmp
[0] = bThemeActive
?'1':'0';
476 RegSetValueExW(hKey
, L
"ThemeActive", 0, REG_SZ
, (const BYTE
*)tmp
, sizeof(WCHAR
)*2);
478 RegSetValueExW(hKey
, L
"ColorName", 0, REG_SZ
, (const BYTE
*)szCurrentColor
,
479 (lstrlenW(szCurrentColor
)+1)*sizeof(WCHAR
));
480 RegSetValueExW(hKey
, L
"SizeName", 0, REG_SZ
, (const BYTE
*)szCurrentSize
,
481 (lstrlenW(szCurrentSize
)+1)*sizeof(WCHAR
));
482 RegSetValueExW(hKey
, L
"DllName", 0, REG_SZ
, (const BYTE
*)szCurrentTheme
,
483 (lstrlenW(szCurrentTheme
)+1)*sizeof(WCHAR
));
486 RegDeleteValueW(hKey
, L
"ColorName");
487 RegDeleteValueW(hKey
, L
"SizeName");
488 RegDeleteValueW(hKey
, L
"DllName");
494 TRACE("Failed to open theme registry key\n");
496 UXTHEME_SaveSystemMetrics ();
501 /***********************************************************************
504 void UXTHEME_InitSystem(HINSTANCE hInst
)
506 atWindowTheme
= GlobalAddAtomW(L
"ux_theme");
507 atSubAppName
= GlobalAddAtomW(L
"ux_subapp");
508 atSubIdList
= GlobalAddAtomW(L
"ux_subidlst");
509 atDialogThemeEnabled
= GlobalAddAtomW(L
"ux_dialogtheme");
515 void UXTHEME_UninitSystem(void)
518 MSSTYLES_SetActiveTheme(NULL
, FALSE
);
520 GlobalDeleteAtom(atWindowTheme
);
521 GlobalDeleteAtom(atSubAppName
);
522 GlobalDeleteAtom(atSubIdList
);
523 GlobalDeleteAtom(atDialogThemeEnabled
);
526 /***********************************************************************
527 * IsAppThemed (UXTHEME.@)
529 BOOL WINAPI
IsAppThemed(void)
531 return IsThemeActive();
534 /***********************************************************************
535 * IsThemeActive (UXTHEME.@)
537 BOOL WINAPI
IsThemeActive(void)
540 SetLastError(ERROR_SUCCESS
);
544 /************************************************************
545 * IsCompositionActive (UXTHEME.@)
547 BOOL WINAPI
IsCompositionActive(void)
551 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
556 /***********************************************************************
557 * EnableTheming (UXTHEME.@)
560 * This is a global and persistent change
562 HRESULT WINAPI
EnableTheming(BOOL fEnable
)
565 WCHAR szEnabled
[] = L
"0";
567 TRACE("(%d)\n", fEnable
);
569 if(fEnable
!= bThemeActive
) {
571 UXTHEME_BackupSystemMetrics();
573 UXTHEME_RestoreSystemMetrics();
574 UXTHEME_SaveSystemMetrics ();
575 bThemeActive
= fEnable
;
576 if(bThemeActive
) szEnabled
[0] = '1';
577 if(!RegOpenKeyW(HKEY_CURRENT_USER
, szThemeManager
, &hKey
)) {
578 RegSetValueExW(hKey
, L
"ThemeActive", 0, REG_SZ
, (BYTE
*)szEnabled
, sizeof(WCHAR
));
581 UXTHEME_broadcast_msg (NULL
, WM_THEMECHANGED
);
586 /***********************************************************************
587 * UXTHEME_SetWindowProperty
589 * I'm using atoms as there may be large numbers of duplicated strings
590 * and they do the work of keeping memory down as a cause of that quite nicely
592 static HRESULT
UXTHEME_SetWindowProperty(HWND hwnd
, ATOM aProp
, LPCWSTR pszValue
)
594 ATOM oldValue
= (ATOM
)(size_t)RemovePropW(hwnd
, (LPCWSTR
)MAKEINTATOM(aProp
));
596 DeleteAtom(oldValue
);
598 ATOM atValue
= AddAtomW(pszValue
);
600 || !SetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(aProp
), (LPWSTR
)MAKEINTATOM(atValue
))) {
601 HRESULT hr
= HRESULT_FROM_WIN32(GetLastError());
602 if(atValue
) DeleteAtom(atValue
);
609 static LPWSTR
UXTHEME_GetWindowProperty(HWND hwnd
, ATOM aProp
, LPWSTR pszBuffer
, int dwLen
)
611 ATOM atValue
= (ATOM
)(size_t)GetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(aProp
));
613 if(GetAtomNameW(atValue
, pszBuffer
, dwLen
))
615 TRACE("property defined, but unable to get value\n");
620 /***********************************************************************
621 * OpenThemeDataEx (UXTHEME.61)
623 HTHEME WINAPI
OpenThemeDataEx(HWND hwnd
, LPCWSTR pszClassList
, DWORD flags
)
625 WCHAR szAppBuff
[256];
626 WCHAR szClassBuff
[256];
628 LPCWSTR pszUseClassList
;
629 HTHEME hTheme
= NULL
;
630 TRACE("(%p,%s, %x)\n", hwnd
, debugstr_w(pszClassList
), flags
);
634 SetLastError(E_POINTER
);
639 FIXME("unhandled flags: %x\n", flags
);
643 pszAppName
= UXTHEME_GetWindowProperty(hwnd
, atSubAppName
, szAppBuff
, ARRAY_SIZE(szAppBuff
));
644 /* If SetWindowTheme was used on the window, that overrides the class list passed to this function */
645 pszUseClassList
= UXTHEME_GetWindowProperty(hwnd
, atSubIdList
, szClassBuff
, ARRAY_SIZE(szClassBuff
));
647 pszUseClassList
= pszClassList
;
650 hTheme
= MSSTYLES_OpenThemeClass(pszAppName
, pszUseClassList
);
652 /* Fall back to default class if the specified subclass is not found */
654 hTheme
= MSSTYLES_OpenThemeClass(NULL
, pszUseClassList
);
657 SetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(atWindowTheme
), hTheme
);
658 TRACE(" = %p\n", hTheme
);
660 SetLastError(hTheme
? ERROR_SUCCESS
: E_PROP_ID_UNSUPPORTED
);
664 /***********************************************************************
665 * OpenThemeData (UXTHEME.@)
667 HTHEME WINAPI
OpenThemeData(HWND hwnd
, LPCWSTR classlist
)
669 return OpenThemeDataEx(hwnd
, classlist
, 0);
672 /***********************************************************************
673 * GetWindowTheme (UXTHEME.@)
675 * Retrieve the last theme opened for a window.
678 * hwnd [I] window to retrieve the theme for
681 * The most recent theme.
683 HTHEME WINAPI
GetWindowTheme(HWND hwnd
)
685 TRACE("(%p)\n", hwnd
);
689 SetLastError(E_HANDLE
);
693 return GetPropW(hwnd
, (LPCWSTR
)MAKEINTATOM(atWindowTheme
));
696 /***********************************************************************
697 * SetWindowTheme (UXTHEME.@)
699 * Persistent through the life of the window, even after themes change
701 HRESULT WINAPI
SetWindowTheme(HWND hwnd
, LPCWSTR pszSubAppName
,
702 LPCWSTR pszSubIdList
)
705 TRACE("(%p,%s,%s)\n", hwnd
, debugstr_w(pszSubAppName
),
706 debugstr_w(pszSubIdList
));
711 hr
= UXTHEME_SetWindowProperty(hwnd
, atSubAppName
, pszSubAppName
);
713 hr
= UXTHEME_SetWindowProperty(hwnd
, atSubIdList
, pszSubIdList
);
715 SendMessageW(hwnd
, WM_THEMECHANGED
, 0, 0);
719 /***********************************************************************
720 * SetWindowThemeAttribute (UXTHEME.@)
722 HRESULT WINAPI
SetWindowThemeAttribute(HWND hwnd
, enum WINDOWTHEMEATTRIBUTETYPE type
,
723 PVOID attribute
, DWORD size
)
725 FIXME("(%p,%d,%p,%d): stub\n", hwnd
, type
, attribute
, size
);
729 /***********************************************************************
730 * GetCurrentThemeName (UXTHEME.@)
732 HRESULT WINAPI
GetCurrentThemeName(LPWSTR pszThemeFileName
, int dwMaxNameChars
,
733 LPWSTR pszColorBuff
, int cchMaxColorChars
,
734 LPWSTR pszSizeBuff
, int cchMaxSizeChars
)
737 return E_PROP_ID_UNSUPPORTED
;
738 if(pszThemeFileName
) lstrcpynW(pszThemeFileName
, szCurrentTheme
, dwMaxNameChars
);
739 if(pszColorBuff
) lstrcpynW(pszColorBuff
, szCurrentColor
, cchMaxColorChars
);
740 if(pszSizeBuff
) lstrcpynW(pszSizeBuff
, szCurrentSize
, cchMaxSizeChars
);
744 /***********************************************************************
745 * GetThemeAppProperties (UXTHEME.@)
747 DWORD WINAPI
GetThemeAppProperties(void)
749 return dwThemeAppProperties
;
752 /***********************************************************************
753 * SetThemeAppProperties (UXTHEME.@)
755 void WINAPI
SetThemeAppProperties(DWORD dwFlags
)
757 TRACE("(0x%08x)\n", dwFlags
);
758 dwThemeAppProperties
= dwFlags
;
761 /***********************************************************************
762 * CloseThemeData (UXTHEME.@)
764 HRESULT WINAPI
CloseThemeData(HTHEME hTheme
)
766 TRACE("(%p)\n", hTheme
);
767 if(!hTheme
|| hTheme
== INVALID_HANDLE_VALUE
)
769 return MSSTYLES_CloseThemeClass(hTheme
);
772 /***********************************************************************
773 * HitTestThemeBackground (UXTHEME.@)
775 HRESULT WINAPI
HitTestThemeBackground(HTHEME hTheme
, HDC hdc
, int iPartId
,
776 int iStateId
, DWORD dwOptions
,
777 const RECT
*pRect
, HRGN hrgn
,
778 POINT ptTest
, WORD
*pwHitTestCode
)
780 FIXME("%d %d 0x%08x: stub\n", iPartId
, iStateId
, dwOptions
);
786 /***********************************************************************
787 * IsThemePartDefined (UXTHEME.@)
789 BOOL WINAPI
IsThemePartDefined(HTHEME hTheme
, int iPartId
, int iStateId
)
791 TRACE("(%p,%d,%d)\n", hTheme
, iPartId
, iStateId
);
793 SetLastError(E_HANDLE
);
796 if(MSSTYLES_FindPartState(hTheme
, iPartId
, iStateId
, NULL
))
801 /***********************************************************************
802 * GetThemeDocumentationProperty (UXTHEME.@)
804 * Try and retrieve the documentation property from string resources
805 * if that fails, get it from the [documentation] section of themes.ini
807 HRESULT WINAPI
GetThemeDocumentationProperty(LPCWSTR pszThemeName
,
808 LPCWSTR pszPropertyName
,
812 static const WORD wDocToRes
[] = {
813 TMT_DISPLAYNAME
,5000,
827 TRACE("(%s,%s,%p,%d)\n", debugstr_w(pszThemeName
), debugstr_w(pszPropertyName
),
828 pszValueBuff
, cchMaxValChars
);
830 hr
= MSSTYLES_OpenThemeFile(pszThemeName
, NULL
, NULL
, &pt
);
831 if(FAILED(hr
)) return hr
;
833 /* Try to load from string resources */
834 hr
= E_PROP_ID_UNSUPPORTED
;
835 if(MSSTYLES_LookupProperty(pszPropertyName
, NULL
, &iDocId
)) {
836 for(i
=0; i
<ARRAY_SIZE(wDocToRes
); i
+=2) {
837 if(wDocToRes
[i
] == iDocId
) {
838 if(LoadStringW(pt
->hTheme
, wDocToRes
[i
+1], pszValueBuff
, cchMaxValChars
)) {
845 /* If loading from string resource failed, try getting it from the theme.ini */
847 PUXINI_FILE uf
= MSSTYLES_GetThemeIni(pt
);
848 if(UXINI_FindSection(uf
, L
"documentation")) {
851 if(UXINI_FindValue(uf
, pszPropertyName
, &lpValue
, &dwLen
)) {
852 lstrcpynW(pszValueBuff
, lpValue
, min(dwLen
+1,cchMaxValChars
));
859 MSSTYLES_CloseThemeFile(pt
);
863 /**********************************************************************
864 * Undocumented functions
867 /**********************************************************************
868 * QueryThemeServices (UXTHEME.1)
871 * some kind of status flag
873 DWORD WINAPI
QueryThemeServices(void)
876 return 3; /* This is what is returned under XP in most cases */
880 /**********************************************************************
881 * OpenThemeFile (UXTHEME.2)
883 * Opens a theme file, which can be used to change the current theme, etc
886 * pszThemeFileName Path to a msstyles theme file
887 * pszColorName Color defined in the theme, eg. NormalColor
888 * pszSizeName Size defined in the theme, eg. NormalSize
889 * hThemeFile Handle to theme file
893 * Failure: HRESULT error-code
895 HRESULT WINAPI
OpenThemeFile(LPCWSTR pszThemeFileName
, LPCWSTR pszColorName
,
896 LPCWSTR pszSizeName
, HTHEMEFILE
*hThemeFile
,
899 TRACE("(%s,%s,%s,%p,%d)\n", debugstr_w(pszThemeFileName
),
900 debugstr_w(pszColorName
), debugstr_w(pszSizeName
),
901 hThemeFile
, unknown
);
902 return MSSTYLES_OpenThemeFile(pszThemeFileName
, pszColorName
, pszSizeName
, (PTHEME_FILE
*)hThemeFile
);
905 /**********************************************************************
906 * CloseThemeFile (UXTHEME.3)
908 * Releases theme file handle returned by OpenThemeFile
911 * hThemeFile Handle to theme file
915 * Failure: HRESULT error-code
917 HRESULT WINAPI
CloseThemeFile(HTHEMEFILE hThemeFile
)
919 TRACE("(%p)\n", hThemeFile
);
920 MSSTYLES_CloseThemeFile(hThemeFile
);
924 /**********************************************************************
925 * ApplyTheme (UXTHEME.4)
927 * Set a theme file to be the currently active theme
930 * hThemeFile Handle to theme file
932 * hWnd Window requesting the theme change
936 * Failure: HRESULT error-code
939 * I'm not sure what the second parameter is (the datatype is likely wrong), other then this:
942 * the theme is applied with the screen redrawing really badly (flickers)
943 * char b[] = "\0"; where \0 can be one or more of any character, makes no difference
944 * the theme is applied smoothly (screen does not flicker)
945 * char *b = "\0" or NULL; where \0 can be zero or more of any character, makes no difference
946 * the function fails returning invalid parameter... very strange
948 HRESULT WINAPI
ApplyTheme(HTHEMEFILE hThemeFile
, char *unknown
, HWND hWnd
)
951 TRACE("(%p,%s,%p)\n", hThemeFile
, unknown
, hWnd
);
952 hr
= UXTHEME_SetActiveTheme(hThemeFile
);
953 UXTHEME_broadcast_msg (NULL
, WM_THEMECHANGED
);
957 /**********************************************************************
958 * GetThemeDefaults (UXTHEME.7)
960 * Get the default color & size for a theme
963 * pszThemeFileName Path to a msstyles theme file
964 * pszColorName Buffer to receive the default color name
965 * dwColorNameLen Length, in characters, of color name buffer
966 * pszSizeName Buffer to receive the default size name
967 * dwSizeNameLen Length, in characters, of size name buffer
971 * Failure: HRESULT error-code
973 HRESULT WINAPI
GetThemeDefaults(LPCWSTR pszThemeFileName
, LPWSTR pszColorName
,
974 DWORD dwColorNameLen
, LPWSTR pszSizeName
,
979 TRACE("(%s,%p,%d,%p,%d)\n", debugstr_w(pszThemeFileName
),
980 pszColorName
, dwColorNameLen
,
981 pszSizeName
, dwSizeNameLen
);
983 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, NULL
, &pt
);
984 if(FAILED(hr
)) return hr
;
986 lstrcpynW(pszColorName
, pt
->pszSelectedColor
, dwColorNameLen
);
987 lstrcpynW(pszSizeName
, pt
->pszSelectedSize
, dwSizeNameLen
);
989 MSSTYLES_CloseThemeFile(pt
);
993 /**********************************************************************
994 * EnumThemes (UXTHEME.8)
996 * Enumerate available themes, calls specified EnumThemeProc for each
997 * theme found. Passes lpData through to callback function.
1000 * pszThemePath Path containing themes
1001 * callback Called for each theme found in path
1002 * lpData Passed through to callback
1006 * Failure: HRESULT error-code
1008 HRESULT WINAPI
EnumThemes(LPCWSTR pszThemePath
, EnumThemeProc callback
,
1011 WCHAR szDir
[MAX_PATH
];
1012 WCHAR szPath
[MAX_PATH
];
1016 WIN32_FIND_DATAW wfd
;
1020 TRACE("(%s,%p,%p)\n", debugstr_w(pszThemePath
), callback
, lpData
);
1022 if(!pszThemePath
|| !callback
)
1025 lstrcpyW(szDir
, pszThemePath
);
1026 pathLen
= lstrlenW (szDir
);
1027 if ((pathLen
> 0) && (pathLen
< MAX_PATH
-1) && (szDir
[pathLen
- 1] != '\\'))
1029 szDir
[pathLen
] = '\\';
1030 szDir
[pathLen
+1] = 0;
1033 lstrcpyW(szPath
, szDir
);
1034 lstrcatW(szPath
, L
"*.*");
1035 TRACE("searching %s\n", debugstr_w(szPath
));
1037 hFind
= FindFirstFileW(szPath
, &wfd
);
1038 if(hFind
!= INVALID_HANDLE_VALUE
) {
1040 if(wfd
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
1041 && !(wfd
.cFileName
[0] == '.' && ((wfd
.cFileName
[1] == '.' && wfd
.cFileName
[2] == 0) || wfd
.cFileName
[1] == 0))) {
1042 wsprintfW(szPath
, L
"%s%s\\%s.msstyles", szDir
, wfd
.cFileName
, wfd
.cFileName
);
1044 hr
= GetThemeDocumentationProperty(szPath
, L
"displayname", szName
, ARRAY_SIZE(szName
));
1046 hr
= GetThemeDocumentationProperty(szPath
, L
"tooltip", szTip
, ARRAY_SIZE(szTip
));
1048 TRACE("callback(%s,%s,%s,%p)\n", debugstr_w(szPath
), debugstr_w(szName
), debugstr_w(szTip
), lpData
);
1049 if(!callback(NULL
, szPath
, szName
, szTip
, NULL
, lpData
)) {
1050 TRACE("callback ended enum\n");
1055 } while(FindNextFileW(hFind
, &wfd
));
1062 /**********************************************************************
1063 * EnumThemeColors (UXTHEME.9)
1065 * Enumerate theme colors available with a particular size
1068 * pszThemeFileName Path to a msstyles theme file
1069 * pszSizeName Theme size to enumerate available colors
1070 * If NULL the default theme size is used
1071 * dwColorNum Color index to retrieve, increment from 0
1072 * pszColorNames Output color names
1076 * E_PROP_ID_UNSUPPORTED when dwColorName does not refer to a color
1077 * or when pszSizeName does not refer to a valid size
1080 * XP fails with E_POINTER when pszColorNames points to a buffer smaller than
1081 * sizeof(THEMENAMES).
1083 * Not very efficient that I'm opening & validating the theme every call, but
1084 * this is undocumented and almost never called..
1085 * (and this is how windows works too)
1087 HRESULT WINAPI
EnumThemeColors(LPWSTR pszThemeFileName
, LPWSTR pszSizeName
,
1088 DWORD dwColorNum
, PTHEMENAMES pszColorNames
)
1093 UINT resourceId
= dwColorNum
+ 1000;
1094 TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName
),
1095 debugstr_w(pszSizeName
), dwColorNum
);
1097 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, pszSizeName
, &pt
);
1098 if(FAILED(hr
)) return hr
;
1100 tmp
= pt
->pszAvailColors
;
1101 while(dwColorNum
&& *tmp
) {
1103 tmp
+= lstrlenW(tmp
)+1;
1105 if(!dwColorNum
&& *tmp
) {
1106 TRACE("%s\n", debugstr_w(tmp
));
1107 lstrcpyW(pszColorNames
->szName
, tmp
);
1108 LoadStringW(pt
->hTheme
, resourceId
, pszColorNames
->szDisplayName
,
1109 ARRAY_SIZE(pszColorNames
->szDisplayName
));
1110 LoadStringW(pt
->hTheme
, resourceId
+1000, pszColorNames
->szTooltip
,
1111 ARRAY_SIZE(pszColorNames
->szTooltip
));
1114 hr
= E_PROP_ID_UNSUPPORTED
;
1116 MSSTYLES_CloseThemeFile(pt
);
1120 /**********************************************************************
1121 * EnumThemeSizes (UXTHEME.10)
1123 * Enumerate theme colors available with a particular size
1126 * pszThemeFileName Path to a msstyles theme file
1127 * pszColorName Theme color to enumerate available sizes
1128 * If NULL the default theme color is used
1129 * dwSizeNum Size index to retrieve, increment from 0
1130 * pszSizeNames Output size names
1134 * E_PROP_ID_UNSUPPORTED when dwSizeName does not refer to a size
1135 * or when pszColorName does not refer to a valid color
1138 * XP fails with E_POINTER when pszSizeNames points to a buffer smaller than
1139 * sizeof(THEMENAMES).
1141 * Not very efficient that I'm opening & validating the theme every call, but
1142 * this is undocumented and almost never called..
1143 * (and this is how windows works too)
1145 HRESULT WINAPI
EnumThemeSizes(LPWSTR pszThemeFileName
, LPWSTR pszColorName
,
1146 DWORD dwSizeNum
, PTHEMENAMES pszSizeNames
)
1151 UINT resourceId
= dwSizeNum
+ 3000;
1152 TRACE("(%s,%s,%d)\n", debugstr_w(pszThemeFileName
),
1153 debugstr_w(pszColorName
), dwSizeNum
);
1155 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, pszColorName
, NULL
, &pt
);
1156 if(FAILED(hr
)) return hr
;
1158 tmp
= pt
->pszAvailSizes
;
1159 while(dwSizeNum
&& *tmp
) {
1161 tmp
+= lstrlenW(tmp
)+1;
1163 if(!dwSizeNum
&& *tmp
) {
1164 TRACE("%s\n", debugstr_w(tmp
));
1165 lstrcpyW(pszSizeNames
->szName
, tmp
);
1166 LoadStringW(pt
->hTheme
, resourceId
, pszSizeNames
->szDisplayName
,
1167 ARRAY_SIZE(pszSizeNames
->szDisplayName
));
1168 LoadStringW(pt
->hTheme
, resourceId
+1000, pszSizeNames
->szTooltip
,
1169 ARRAY_SIZE(pszSizeNames
->szTooltip
));
1172 hr
= E_PROP_ID_UNSUPPORTED
;
1174 MSSTYLES_CloseThemeFile(pt
);
1178 /**********************************************************************
1179 * ParseThemeIniFile (UXTHEME.11)
1181 * Enumerate data in a theme INI file.
1184 * pszIniFileName Path to a theme ini file
1185 * pszUnknown Cannot be NULL, L"" is valid
1186 * callback Called for each found entry
1187 * lpData Passed through to callback
1191 * 0x800706488 (Unknown property) when enumeration is canceled from callback
1194 * When pszUnknown is NULL the callback is never called, the value does not seem to serve
1197 HRESULT WINAPI
ParseThemeIniFile(LPCWSTR pszIniFileName
, LPWSTR pszUnknown
,
1198 ParseThemeIniFileProc callback
, LPVOID lpData
)
1200 FIXME("%s %s: stub\n", debugstr_w(pszIniFileName
), debugstr_w(pszUnknown
));
1204 /**********************************************************************
1205 * CheckThemeSignature (UXTHEME.29)
1207 * Validates the signature of a theme file
1210 * pszIniFileName Path to a theme file
1214 * Failure: HRESULT error-code
1216 HRESULT WINAPI
CheckThemeSignature(LPCWSTR pszThemeFileName
)
1220 TRACE("(%s)\n", debugstr_w(pszThemeFileName
));
1221 hr
= MSSTYLES_OpenThemeFile(pszThemeFileName
, NULL
, NULL
, &pt
);
1224 MSSTYLES_CloseThemeFile(pt
);
1228 BOOL WINAPI
ThemeHooksInstall(void)
1230 struct user_api_hook hooks
;
1232 hooks
.pDefDlgProc
= UXTHEME_DefDlgProc
;
1233 hooks
.pScrollBarDraw
= UXTHEME_ScrollBarDraw
;
1234 hooks
.pScrollBarWndProc
= UXTHEME_ScrollbarWndProc
;
1235 return RegisterUserApiHook(&hooks
, &user_api
);
1238 BOOL WINAPI
ThemeHooksRemove(void)
1240 UnregisterUserApiHook();