VisualStylesXP.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Copyright (C) 2001-2002 by David Yuheng Zhao
  3. //
  4. // Distribute and change freely, except: don't remove my name from the source
  5. //
  6. // No warrantee of any kind, express or implied, is included with this
  7. // software; use at your own risk, responsibility for damages (if any) to
  8. // anyone resulting from the use of this software rests entirely with the
  9. // user.
  10. //
  11. // Partly based on the _ThemeHelper struct in MFC7.0 source code (winctrl3.cpp),
  12. // and the difference is that this implementation wraps the full set of
  13. // visual style APIs from the platform SDK August 2001
  14. //
  15. // If you have any questions, I can be reached as follows:
  16. // yuheng_zhao@yahoo.com
  17. //
  18. //
  19. // How to use:
  20. // Instead of calling the API directly,
  21. // OpenThemeData(...);
  22. // use the global variable
  23. // g_xpStyle.OpenThemeData(...);
  24. //
  25. //
  26. //
  27. // Date: 2002-07-27
  28. // This update was made by Mathias Tunared.
  29. // He changed the function variable to static to make the code faster.
  30. // He also added the function 'UseVisualStyles()' so you can check if to
  31. // draw with the visual styles or not. That function checks first the
  32. // version of the 'ComCtl32.dll' and the checks if the theme is activated
  33. // and the HTHEME handle is not NULL.
  34. //
  35. // CAdvComboBox Control
  36. // Version: 2.1
  37. // Date: August 2002
  38. // Author: Mathias Tunared
  39. // Email: Mathias@inorbit.com
  40. //
  41. // This file is provided "as is" with no expressed or implied warranty.
  42. // The author accepts no liability for any damage/loss of business that
  43. // this product may cause.
  44. //
  45. /////////////////////////////////////////////////////////////////////////////
  46. #include "stdafx.h"
  47. #include "visualstylesxp.h"
  48. #include <Shlwapi.h>
  49. CVisualStylesXP g_xpStyle;
  50. CVisualStylesXP::CVisualStylesXP(void)
  51. {
  52. m_hThemeDll = LoadLibrary(_T("UxTheme.dll"));
  53. }
  54. CVisualStylesXP::~CVisualStylesXP(void)
  55. {
  56. if (m_hThemeDll!=NULL)
  57. FreeLibrary(m_hThemeDll);
  58. m_hThemeDll = NULL;
  59. }
  60. void* CVisualStylesXP::GetProc(LPCSTR szProc, void* pfnFail)
  61. {
  62. void* pRet = pfnFail;
  63. if (m_hThemeDll != NULL)
  64. pRet = GetProcAddress(m_hThemeDll, szProc);
  65. return pRet;
  66. }
  67. HTHEME CVisualStylesXP::OpenThemeData(HWND hwnd, LPCWSTR pszClassList)
  68. {
  69. static PFNOPENTHEMEDATA pfnOpenThemeData = NULL;
  70. if( !pfnOpenThemeData )
  71. pfnOpenThemeData = (PFNOPENTHEMEDATA)GetProc("OpenThemeData", (void*)OpenThemeDataFail);
  72. return (*pfnOpenThemeData)(hwnd, pszClassList);
  73. }
  74. HRESULT CVisualStylesXP::CloseThemeData(HTHEME hTheme)
  75. {
  76. static PFNCLOSETHEMEDATA pfnCloseThemeData = NULL;
  77. if( !pfnCloseThemeData )
  78. pfnCloseThemeData = (PFNCLOSETHEMEDATA)GetProc("CloseThemeData", (void*)CloseThemeDataFail);
  79. return (*pfnCloseThemeData)(hTheme);
  80. }
  81. HRESULT CVisualStylesXP::DrawThemeBackground(HTHEME hTheme, HDC hdc,
  82. int iPartId, int iStateId, const RECT *pRect, const RECT *pClipRect)
  83. {
  84. static PFNDRAWTHEMEBACKGROUND pfnDrawThemeBackground = NULL;
  85. if( !pfnDrawThemeBackground )
  86. pfnDrawThemeBackground = (PFNDRAWTHEMEBACKGROUND)GetProc("DrawThemeBackground", (void*)DrawThemeBackgroundFail);
  87. return (*pfnDrawThemeBackground)(hTheme, hdc, iPartId, iStateId, pRect, pClipRect);
  88. }
  89. HRESULT CVisualStylesXP::DrawThemeText(HTHEME hTheme, HDC hdc, int iPartId,
  90. int iStateId, LPCWSTR pszText, int iCharCount, DWORD dwTextFlags,
  91. DWORD dwTextFlags2, const RECT *pRect)
  92. {
  93. static PFNDRAWTHEMETEXT pfn = NULL;
  94. if( !pfn )
  95. pfn = (PFNDRAWTHEMETEXT)GetProc("DrawThemeText", (void*)DrawThemeTextFail);
  96. return (*pfn)(hTheme, hdc, iPartId, iStateId, pszText, iCharCount, dwTextFlags, dwTextFlags2, pRect);
  97. }
  98. HRESULT CVisualStylesXP::GetThemeBackgroundContentRect(HTHEME hTheme, HDC hdc,
  99. int iPartId, int iStateId, const RECT *pBoundingRect,
  100. RECT *pContentRect)
  101. {
  102. static PFNGETTHEMEBACKGROUNDCONTENTRECT pfn = NULL;
  103. if( !pfn )
  104. pfn = (PFNGETTHEMEBACKGROUNDCONTENTRECT)GetProc("GetThemeBackgroundContentRect", (void*)GetThemeBackgroundContentRectFail);
  105. return (*pfn)(hTheme, hdc, iPartId, iStateId, pBoundingRect, pContentRect);
  106. }
  107. HRESULT CVisualStylesXP::GetThemeBackgroundExtent(HTHEME hTheme, HDC hdc,
  108. int iPartId, int iStateId, const RECT *pContentRect,
  109. RECT *pExtentRect)
  110. {
  111. static PFNGETTHEMEBACKGROUNDEXTENT pfn = NULL;
  112. if( !pfn )
  113. pfn = (PFNGETTHEMEBACKGROUNDEXTENT)GetProc("GetThemeBackgroundExtent", (void*)GetThemeBackgroundExtentFail);
  114. return (*pfn)(hTheme, hdc, iPartId, iStateId, pContentRect, pExtentRect);
  115. }
  116. HRESULT CVisualStylesXP::GetThemePartSize(HTHEME hTheme, HDC hdc,
  117. int iPartId, int iStateId, RECT * pRect, enum THEMESIZE eSize, SIZE *psz)
  118. {
  119. static PFNGETTHEMEPARTSIZE pfnGetThemePartSize = NULL;
  120. if( !pfnGetThemePartSize )
  121. pfnGetThemePartSize = (PFNGETTHEMEPARTSIZE)GetProc("GetThemePartSize", (void*)GetThemePartSizeFail);
  122. return (*pfnGetThemePartSize)(hTheme, hdc, iPartId, iStateId, pRect, eSize, psz);
  123. }
  124. HRESULT CVisualStylesXP::GetThemeTextExtent(HTHEME hTheme, HDC hdc,
  125. int iPartId, int iStateId, LPCWSTR pszText, int iCharCount,
  126. DWORD dwTextFlags, const RECT *pBoundingRect,
  127. RECT *pExtentRect)
  128. {
  129. static PFNGETTHEMETEXTEXTENT pfn = NULL;
  130. if( !pfn )
  131. pfn = (PFNGETTHEMETEXTEXTENT)GetProc("GetThemeTextExtent", (void*)GetThemeTextExtentFail);
  132. return (*pfn)(hTheme, hdc, iPartId, iStateId, pszText, iCharCount, dwTextFlags, pBoundingRect, pExtentRect);
  133. }
  134. HRESULT CVisualStylesXP::GetThemeTextMetrics(HTHEME hTheme, HDC hdc,
  135. int iPartId, int iStateId, TEXTMETRIC* ptm)
  136. {
  137. static PFNGETTHEMETEXTMETRICS pfn = NULL;
  138. if( !pfn )
  139. pfn = (PFNGETTHEMETEXTMETRICS)GetProc("GetThemeTextMetrics", (void*)GetThemeTextMetricsFail);
  140. return (*pfn)(hTheme, hdc, iPartId, iStateId, ptm);
  141. }
  142. HRESULT CVisualStylesXP::GetThemeBackgroundRegion(HTHEME hTheme, HDC hdc,
  143. int iPartId, int iStateId, const RECT *pRect, HRGN *pRegion)
  144. {
  145. static PFNGETTHEMEBACKGROUNDREGION pfn = NULL;
  146. if( !pfn )
  147. pfn = (PFNGETTHEMEBACKGROUNDREGION)GetProc("GetThemeBackgroundRegion", (void*)GetThemeBackgroundRegionFail);
  148. return (*pfn)(hTheme, hdc, iPartId, iStateId, pRect, pRegion);
  149. }
  150. HRESULT CVisualStylesXP::HitTestThemeBackground(HTHEME hTheme, HDC hdc, int iPartId,
  151. int iStateId, DWORD dwOptions, const RECT *pRect, HRGN hrgn,
  152. POINT ptTest, WORD *pwHitTestCode)
  153. {
  154. static PFNHITTESTTHEMEBACKGROUND pfn = NULL;
  155. if( !pfn )
  156. pfn = (PFNHITTESTTHEMEBACKGROUND)GetProc("HitTestThemeBackground", (void*)HitTestThemeBackgroundFail);
  157. return (*pfn)(hTheme, hdc, iPartId, iStateId, dwOptions, pRect, hrgn, ptTest, pwHitTestCode);
  158. }
  159. HRESULT CVisualStylesXP::DrawThemeEdge(HTHEME hTheme, HDC hdc, int iPartId, int iStateId,
  160. const RECT *pDestRect, UINT uEdge, UINT uFlags, RECT *pContentRect)
  161. {
  162. static PFNDRAWTHEMEEDGE pfn = NULL;
  163. if( !pfn )
  164. pfn = (PFNDRAWTHEMEEDGE)GetProc("DrawThemeEdge", (void*)DrawThemeEdgeFail);
  165. return (*pfn)(hTheme, hdc, iPartId, iStateId, pDestRect, uEdge, uFlags, pContentRect);
  166. }
  167. HRESULT CVisualStylesXP::DrawThemeIcon(HTHEME hTheme, HDC hdc, int iPartId,
  168. int iStateId, const RECT *pRect, HIMAGELIST himl, int iImageIndex)
  169. {
  170. static PFNDRAWTHEMEICON pfn = NULL;
  171. if( !pfn )
  172. pfn = (PFNDRAWTHEMEICON)GetProc("DrawThemeIcon", (void*)DrawThemeIconFail);
  173. return (*pfn)(hTheme, hdc, iPartId, iStateId, pRect, himl, iImageIndex);
  174. }
  175. BOOL CVisualStylesXP::IsThemePartDefined(HTHEME hTheme, int iPartId,
  176. int iStateId)
  177. {
  178. static PFNISTHEMEPARTDEFINED pfn = NULL;
  179. if( !pfn )
  180. pfn = (PFNISTHEMEPARTDEFINED)GetProc("IsThemePartDefined", (void*)IsThemePartDefinedFail);
  181. return (*pfn)(hTheme, iPartId, iStateId);
  182. }
  183. BOOL CVisualStylesXP::IsThemeBackgroundPartiallyTransparent(HTHEME hTheme,
  184. int iPartId, int iStateId)
  185. {
  186. static PFNISTHEMEBACKGROUNDPARTIALLYTRANSPARENT pfn = NULL;
  187. if( !pfn )
  188. pfn = (PFNISTHEMEBACKGROUNDPARTIALLYTRANSPARENT)GetProc("IsThemeBackgroundPartiallyTransparent", (void*)IsThemeBackgroundPartiallyTransparentFail);
  189. return (*pfn)(hTheme, iPartId, iStateId);
  190. }
  191. HRESULT CVisualStylesXP::GetThemeColor(HTHEME hTheme, int iPartId,
  192. int iStateId, int iPropId, COLORREF *pColor)
  193. {
  194. static PFNGETTHEMECOLOR pfn = NULL;
  195. if( !pfn )
  196. pfn = (PFNGETTHEMECOLOR)GetProc("GetThemeColor", (void*)GetThemeColorFail);
  197. return (*pfn)(hTheme, iPartId, iStateId, iPropId, pColor);
  198. }
  199. HRESULT CVisualStylesXP::GetThemeMetric(HTHEME hTheme, HDC hdc, int iPartId,
  200. int iStateId, int iPropId, int *piVal)
  201. {
  202. static PFNGETTHEMEMETRIC pfn = NULL;
  203. if( !pfn )
  204. pfn = (PFNGETTHEMEMETRIC)GetProc("GetThemeMetric", (void*)GetThemeMetricFail);
  205. return (*pfn)(hTheme, hdc, iPartId, iStateId, iPropId, piVal);
  206. }
  207. HRESULT CVisualStylesXP::GetThemeString(HTHEME hTheme,
  208. int iPartId,
  209. int iStateId,
  210. int iPropId,
  211. LPWSTR pszBuff,
  212. int cchMaxBuffChars)
  213. {
  214. static PFNGETTHEMESTRING pfn = NULL;
  215. if( !pfn )
  216. pfn = (PFNGETTHEMESTRING)GetProc("GetThemeString", (void*)GetThemeStringFail);
  217. return (*pfn)(hTheme, iPartId, iStateId, iPropId, pszBuff, cchMaxBuffChars);
  218. }
  219. HRESULT CVisualStylesXP::GetThemeBool(HTHEME hTheme, int iPartId,
  220. int iStateId, int iPropId, BOOL *pfVal)
  221. {
  222. static PFNGETTHEMEBOOL pfn = NULL;
  223. if( !pfn )
  224. pfn = (PFNGETTHEMEBOOL)GetProc("GetThemeBool", (void*)GetThemeBoolFail);
  225. return (*pfn)(hTheme, iPartId, iStateId, iPropId, pfVal);
  226. }
  227. HRESULT CVisualStylesXP::GetThemeInt(HTHEME hTheme, int iPartId,
  228. int iStateId, int iPropId, int *piVal)
  229. {
  230. static PFNGETTHEMEINT pfn = NULL;
  231. if( !pfn )
  232. pfn = (PFNGETTHEMEINT)GetProc("GetThemeInt", (void*)GetThemeIntFail);
  233. return (*pfn)(hTheme, iPartId, iStateId, iPropId, piVal);
  234. }
  235. HRESULT CVisualStylesXP::GetThemeEnumValue(HTHEME hTheme, int iPartId,
  236. int iStateId, int iPropId, int *piVal)
  237. {
  238. static PFNGETTHEMEENUMVALUE pfn = NULL;
  239. if( !pfn )
  240. pfn = (PFNGETTHEMEENUMVALUE)GetProc("GetThemeEnumValue", (void*)GetThemeEnumValueFail);
  241. return (*pfn)(hTheme, iPartId, iStateId, iPropId, piVal);
  242. }
  243. HRESULT CVisualStylesXP::GetThemePosition(HTHEME hTheme, int iPartId,
  244. int iStateId, int iPropId, POINT *pPoint)
  245. {
  246. static PFNGETTHEMEPOSITION pfn = NULL;
  247. if( !pfn )
  248. pfn = (PFNGETTHEMEPOSITION)GetProc("GetThemePosition", (void*)GetThemePositionFail);
  249. return (*pfn)(hTheme, iPartId, iStateId, iPropId, pPoint);
  250. }
  251. HRESULT CVisualStylesXP::GetThemeFont(HTHEME hTheme, HDC hdc, int iPartId,
  252. int iStateId, int iPropId, LOGFONT *pFont)
  253. {
  254. static PFNGETTHEMEFONT pfn = NULL;
  255. if( !pfn )
  256. pfn = (PFNGETTHEMEFONT)GetProc("GetThemeFont", (void*)GetThemeFontFail);
  257. return (*pfn)(hTheme, hdc, iPartId, iStateId, iPropId, pFont);
  258. }
  259. HRESULT CVisualStylesXP::GetThemeRect(HTHEME hTheme, int iPartId,
  260. int iStateId, int iPropId, RECT *pRect)
  261. {
  262. static PFNGETTHEMERECT pfn = NULL;
  263. if( !pfn )
  264. pfn = (PFNGETTHEMERECT)GetProc("GetThemeRect", (void*)GetThemeRectFail);
  265. return (*pfn)(hTheme, iPartId, iStateId, iPropId, pRect);
  266. }
  267. HRESULT CVisualStylesXP::GetThemeMargins(HTHEME hTheme, HDC hdc, int iPartId,
  268. int iStateId, int iPropId, RECT *prc, MARGINS *pMargins)
  269. {
  270. static PFNGETTHEMEMARGINS pfn = NULL;
  271. if( !pfn )
  272. pfn = (PFNGETTHEMEMARGINS)GetProc("GetThemeMargins", (void*)GetThemeMarginsFail);
  273. return (*pfn)(hTheme, hdc, iPartId, iStateId, iPropId, prc, pMargins);
  274. }
  275. HRESULT CVisualStylesXP::GetThemeIntList(HTHEME hTheme, int iPartId,
  276. int iStateId, int iPropId, INTLIST *pIntList)
  277. {
  278. static PFNGETTHEMEINTLIST pfn = NULL;
  279. if( !pfn )
  280. pfn = (PFNGETTHEMEINTLIST)GetProc("GetThemeIntList", (void*)GetThemeIntListFail);
  281. return (*pfn)(hTheme, iPartId, iStateId, iPropId, pIntList);
  282. }
  283. HRESULT CVisualStylesXP::GetThemePropertyOrigin(HTHEME hTheme, int iPartId,
  284. int iStateId, int iPropId, enum PROPERTYORIGIN *pOrigin)
  285. {
  286. static PFNGETTHEMEPROPERTYORIGIN pfn = NULL;
  287. if( !pfn )
  288. pfn = (PFNGETTHEMEPROPERTYORIGIN)GetProc("GetThemePropertyOrigin", (void*)GetThemePropertyOriginFail);
  289. return (*pfn)(hTheme, iPartId, iStateId, iPropId, pOrigin);
  290. }
  291. HRESULT CVisualStylesXP::SetWindowTheme(HWND hwnd, LPCWSTR pszSubAppName,
  292. LPCWSTR pszSubIdList)
  293. {
  294. static PFNSETWINDOWTHEME pfn = NULL;
  295. if( !pfn )
  296. pfn = (PFNSETWINDOWTHEME)GetProc("SetWindowTheme", (void*)SetWindowThemeFail);
  297. return (*pfn)(hwnd, pszSubAppName, pszSubIdList);
  298. }
  299. HRESULT CVisualStylesXP::GetThemeFilename(HTHEME hTheme, int iPartId,
  300. int iStateId, int iPropId, LPWSTR pszThemeFileName, int cchMaxBuffChars)
  301. {
  302. static PFNGETTHEMEFILENAME pfn = NULL;
  303. if( !pfn )
  304. pfn = (PFNGETTHEMEFILENAME)GetProc("GetThemeFilename", (void*)GetThemeFilenameFail);
  305. return (*pfn)(hTheme, iPartId, iStateId, iPropId, pszThemeFileName, cchMaxBuffChars);
  306. }
  307. COLORREF CVisualStylesXP::GetThemeSysColor(HTHEME hTheme, int iColorId)
  308. {
  309. static PFNGETTHEMESYSCOLOR pfn = NULL;
  310. if( !pfn )
  311. pfn = (PFNGETTHEMESYSCOLOR)GetProc("GetThemeSysColor", (void*)GetThemeSysColorFail);
  312. return (*pfn)(hTheme, iColorId);
  313. }
  314. HBRUSH CVisualStylesXP::GetThemeSysColorBrush(HTHEME hTheme, int iColorId)
  315. {
  316. static PFNGETTHEMESYSCOLORBRUSH pfn = NULL;
  317. if( !pfn )
  318. pfn = (PFNGETTHEMESYSCOLORBRUSH)GetProc("GetThemeSysColorBrush", (void*)GetThemeSysColorBrushFail);
  319. return (*pfn)(hTheme, iColorId);
  320. }
  321. BOOL CVisualStylesXP::GetThemeSysBool(HTHEME hTheme, int iBoolId)
  322. {
  323. static PFNGETTHEMESYSBOOL pfn = NULL;
  324. if( !pfn )
  325. pfn = (PFNGETTHEMESYSBOOL)GetProc("GetThemeSysBool", (void*)GetThemeSysBoolFail);
  326. return (*pfn)(hTheme, iBoolId);
  327. }
  328. int CVisualStylesXP::GetThemeSysSize(HTHEME hTheme, int iSizeId)
  329. {
  330. static PFNGETTHEMESYSSIZE pfn = NULL;
  331. if( !pfn )
  332. pfn = (PFNGETTHEMESYSSIZE)GetProc("GetThemeSysSize", (void*)GetThemeSysSizeFail);
  333. return (*pfn)(hTheme, iSizeId);
  334. }
  335. HRESULT CVisualStylesXP::GetThemeSysFont(HTHEME hTheme, int iFontId, LOGFONT *plf)
  336. {
  337. static PFNGETTHEMESYSFONT pfn = NULL;
  338. if( !pfn )
  339. pfn = (PFNGETTHEMESYSFONT)GetProc("GetThemeSysFont", (void*)GetThemeSysFontFail);
  340. return (*pfn)(hTheme, iFontId, plf);
  341. }
  342. HRESULT CVisualStylesXP::GetThemeSysString(HTHEME hTheme, int iStringId,
  343. LPWSTR pszStringBuff, int cchMaxStringChars)
  344. {
  345. static PFNGETTHEMESYSSTRING pfn = NULL;
  346. if( !pfn )
  347. pfn = (PFNGETTHEMESYSSTRING)GetProc("GetThemeSysString", (void*)GetThemeSysStringFail);
  348. return (*pfn)(hTheme, iStringId, pszStringBuff, cchMaxStringChars);
  349. }
  350. HRESULT CVisualStylesXP::GetThemeSysInt(HTHEME hTheme, int iIntId, int *piValue)
  351. {
  352. static PFNGETTHEMESYSINT pfn = NULL;
  353. if( !pfn )
  354. pfn = (PFNGETTHEMESYSINT)GetProc("GetThemeSysInt", (void*)GetThemeSysIntFail);
  355. return (*pfn)(hTheme, iIntId, piValue);
  356. }
  357. BOOL CVisualStylesXP::IsThemeActive()
  358. {
  359. static PFNISTHEMEACTIVE pfn = NULL;
  360. if( !pfn )
  361. pfn = (PFNISTHEMEACTIVE)GetProc("IsThemeActive", (void*)IsThemeActiveFail);
  362. return (*pfn)();
  363. }
  364. BOOL CVisualStylesXP::IsAppThemed()
  365. {
  366. static PFNISAPPTHEMED pfnIsAppThemed = NULL;
  367. if( !pfnIsAppThemed )
  368. pfnIsAppThemed = (PFNISAPPTHEMED)GetProc("IsAppThemed", (void*)IsAppThemedFail);
  369. return (*pfnIsAppThemed)();
  370. }
  371. HTHEME CVisualStylesXP::GetWindowTheme(HWND hwnd)
  372. {
  373. static PFNGETWINDOWTHEME pfn = NULL;
  374. if( !pfn )
  375. pfn = (PFNGETWINDOWTHEME)GetProc("GetWindowTheme", (void*)GetWindowThemeFail);
  376. return (*pfn)(hwnd);
  377. }
  378. HRESULT CVisualStylesXP::EnableThemeDialogTexture(HWND hwnd, DWORD dwFlags)
  379. {
  380. static PFNENABLETHEMEDIALOGTEXTURE pfn = NULL;
  381. if( !pfn )
  382. pfn = (PFNENABLETHEMEDIALOGTEXTURE)GetProc("EnableThemeDialogTexture", (void*)EnableThemeDialogTextureFail);
  383. return (*pfn)(hwnd, dwFlags);
  384. }
  385. BOOL CVisualStylesXP::IsThemeDialogTextureEnabled(HWND hwnd)
  386. {
  387. static PFNISTHEMEDIALOGTEXTUREENABLED pfn = NULL;
  388. if( !pfn )
  389. pfn = (PFNISTHEMEDIALOGTEXTUREENABLED)GetProc("IsThemeDialogTextureEnabled", (void*)IsThemeDialogTextureEnabledFail);
  390. return (*pfn)(hwnd);
  391. }
  392. DWORD CVisualStylesXP::GetThemeAppProperties()
  393. {
  394. static PFNGETTHEMEAPPPROPERTIES pfn = NULL;
  395. if( !pfn )
  396. pfn = (PFNGETTHEMEAPPPROPERTIES)GetProc("GetThemeAppProperties", (void*)GetThemeAppPropertiesFail);
  397. return (*pfn)();
  398. }
  399. void CVisualStylesXP::SetThemeAppProperties(DWORD dwFlags)
  400. {
  401. static PFNSETTHEMEAPPPROPERTIES pfn = NULL;
  402. if( !pfn )
  403. pfn = (PFNSETTHEMEAPPPROPERTIES)GetProc("SetThemeAppProperties", (void*)SetThemeAppPropertiesFail);
  404. (*pfn)(dwFlags);
  405. }
  406. HRESULT CVisualStylesXP::GetCurrentThemeName(
  407. LPWSTR pszThemeFileName, int cchMaxNameChars,
  408. LPWSTR pszColorBuff, int cchMaxColorChars,
  409. LPWSTR pszSizeBuff, int cchMaxSizeChars)
  410. {
  411. static PFNGETCURRENTTHEMENAME pfn = NULL;
  412. if( !pfn )
  413. pfn = (PFNGETCURRENTTHEMENAME)GetProc("GetCurrentThemeName", (void*)GetCurrentThemeNameFail);
  414. return (*pfn)(pszThemeFileName, cchMaxNameChars, pszColorBuff, cchMaxColorChars, pszSizeBuff, cchMaxSizeChars);
  415. }
  416. HRESULT CVisualStylesXP::GetThemeDocumentationProperty(LPCWSTR pszThemeName,
  417. LPCWSTR pszPropertyName, LPWSTR pszValueBuff, int cchMaxValChars)
  418. {
  419. static PFNGETTHEMEDOCUMENTATIONPROPERTY pfn = NULL;
  420. if( !pfn )
  421. pfn = (PFNGETTHEMEDOCUMENTATIONPROPERTY)GetProc("GetThemeDocumentationProperty", (void*)GetThemeDocumentationPropertyFail);
  422. return (*pfn)(pszThemeName, pszPropertyName, pszValueBuff, cchMaxValChars);
  423. }
  424. HRESULT CVisualStylesXP::DrawThemeParentBackground(HWND hwnd, HDC hdc, RECT* prc)
  425. {
  426. static PFNDRAWTHEMEPARENTBACKGROUND pfn = NULL;
  427. if( !pfn )
  428. pfn = (PFNDRAWTHEMEPARENTBACKGROUND)GetProc("DrawThemeParentBackground", (void*)DrawThemeParentBackgroundFail);
  429. return (*pfn)(hwnd, hdc, prc);
  430. }
  431. HRESULT CVisualStylesXP::EnableTheming(BOOL fEnable)
  432. {
  433. static PFNENABLETHEMING pfn = NULL;
  434. if( !pfn )
  435. pfn = (PFNENABLETHEMING)GetProc("EnableTheming", (void*)EnableThemingFail);
  436. return (*pfn)(fEnable);
  437. }
  438. /////////////////////////////////////////////////////////////////////////////
  439. // Added by Mathias Tunared 2002-07-27
  440. //
  441. BOOL CVisualStylesXP::UseVisualStyles()
  442. {
  443. static BOOL bUse = -1;
  444. if( bUse != -1 )
  445. return bUse;
  446. HINSTANCE hinstDll;
  447. DLLVERSIONINFO dvi;
  448. ZeroMemory(&dvi, sizeof(dvi));
  449. hinstDll = LoadLibrary(TEXT("comctl32.dll"));
  450. if(hinstDll)
  451. {
  452. DLLGETVERSIONPROC pDllGetVersion;
  453. pDllGetVersion = (DLLGETVERSIONPROC) GetProcAddress(hinstDll, "DllGetVersion");
  454. if(pDllGetVersion)
  455. {
  456. ZeroMemory(&dvi, sizeof(dvi));
  457. dvi.cbSize = sizeof(dvi);
  458. (*pDllGetVersion)(&dvi);
  459. }
  460. FreeLibrary(hinstDll);
  461. }
  462. if( dvi.dwMajorVersion == 6 && dvi.dwMinorVersion == 0 )
  463. {
  464. //+++
  465. WCHAR szName [256];
  466. WCHAR szColor [256];
  467. if (!GetCurrentThemeName(szName, 255, szColor, 255, NULL, 0))
  468. {
  469. CString strWinXPThemeColor = szColor;
  470. if (strWinXPThemeColor.CompareNoCase (_T("normalcolor")) == 0 ||
  471. strWinXPThemeColor.CompareNoCase (_T("homestead")) == 0 ||
  472. strWinXPThemeColor.CompareNoCase (_T("metallic")) == 0)
  473. {
  474. bUse = TRUE;
  475. return IsAppThemed() && m_hThemeDll; // No need to test HTHEME, but...
  476. }
  477. }
  478. }
  479. bUse = FALSE;
  480. return FALSE;
  481. }