XTPWinThemeWrapper.cpp
上传用户:szled88
上传日期:2015-04-09
资源大小:43957k
文件大小:20k
源码类别:

对话框与窗口

开发平台:

Visual C++

  1. // XTPWinThemeWrapper.cpp: implementation of the CXTPWinThemeWrapper class.
  2. //
  3. // This file is a part of the XTREME TOOLKIT PRO MFC class library.
  4. // (c)1998-2008 Codejock Software, All Rights Reserved.
  5. //
  6. // THIS SOURCE FILE IS THE PROPERTY OF CODEJOCK SOFTWARE AND IS NOT TO BE
  7. // RE-DISTRIBUTED BY ANY MEANS WHATSOEVER WITHOUT THE EXPRESSED WRITTEN
  8. // CONSENT OF CODEJOCK SOFTWARE.
  9. //
  10. // THIS SOURCE CODE CAN ONLY BE USED UNDER THE TERMS AND CONDITIONS OUTLINED
  11. // IN THE XTREME TOOLKIT PRO LICENSE AGREEMENT. CODEJOCK SOFTWARE GRANTS TO
  12. // YOU (ONE SOFTWARE DEVELOPER) THE LIMITED RIGHT TO USE THIS SOFTWARE ON A
  13. // SINGLE COMPUTER.
  14. //
  15. // CONTACT INFORMATION:
  16. // support@codejock.com
  17. // http://www.codejock.com
  18. //
  19. /////////////////////////////////////////////////////////////////////////////
  20. #include "stdafx.h"
  21. #include "XTPWinThemeWrapper.h"
  22. #include "XTPSystemHelpers.h"
  23. #ifdef _DEBUG
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #define new DEBUG_NEW
  27. #endif
  28. #pragma warning(disable: 4571) // warning C4571: catch(...) blocks compiled with /EHs do not catch or re-throw Structured Exceptions
  29. #define TRY_POINTER_CALL(proc)
  30. try
  31. {
  32. CSharedData& sData = GetSharedData();
  33. if (sData.m_hThemeDll != NULL && sData.m_ptrWrappers[xtpWrapper##proc] == NULL)
  34. {
  35. sData.m_ptrWrappers[xtpWrapper##proc] = ::GetProcAddress(
  36. sData.m_hThemeDll, xtpWrapperProc##proc);
  37. }
  38. PFN##proc ptr = (PFN##proc)sData.m_ptrWrappers[xtpWrapper##proc];
  39. if (ptr)
  40. {
  41. #define POINTER_CALL (*ptr)
  42. #define CATCH_POINTER_CALL()
  43. }
  44. }
  45. catch (...)
  46. {
  47. }
  48. BOOL CXTPWinThemeWrapper::m_bDllDetached = FALSE;
  49. CXTPWinThemeWrapper::CSharedData::CSharedData()
  50. {
  51. m_dwComCtlVersion = XTPSystemVersion()->GetComCtlVersion();
  52. ZeroMemory(&m_ptrWrappers, sizeof(m_ptrWrappers));
  53. m_hThemeDll = ::LoadLibrary(_T("UXTHEME.DLL"));
  54. }
  55. CXTPWinThemeWrapper::CSharedData& CXTPWinThemeWrapper::GetSharedData() const
  56. {
  57. if (m_pSharedDara)
  58. return (CSharedData&)*m_pSharedDara;
  59. if (!m_bUseSkinFramework)
  60. {
  61. static CSharedData sDataSystem;
  62. return sDataSystem;
  63. }
  64. static CSharedData sData;
  65. return sData;
  66. }
  67. void CXTPWinThemeWrapper::CreateSharedData()
  68. {
  69. SAFE_DELETE(m_pSharedDara);
  70. m_pSharedDara = new CSharedData();
  71. }
  72. //===========================================================================
  73. // CXTPWinThemeWrapper class
  74. //===========================================================================
  75. CXTPWinThemeWrapper::CXTPWinThemeWrapper(BOOL bUseSkinFramework)
  76. : m_hTheme(NULL), m_bUseSkinFramework(bUseSkinFramework), m_pSharedDara(0)
  77. {
  78. }
  79. CXTPWinThemeWrapper::~CXTPWinThemeWrapper()
  80. {
  81. CloseThemeData();
  82. SAFE_DELETE(m_pSharedDara);
  83. }
  84. void CXTPWinThemeWrapper::ReloadLibrary() const
  85. {
  86. if (!m_bUseSkinFramework)
  87. return;
  88. HMODULE hThemeDll = GetModuleHandleA("UXTHEME.DLL");
  89. CSharedData& sData = GetSharedData();
  90. if (hThemeDll != sData.m_hThemeDll)
  91. {
  92. sData.m_hThemeDll = hThemeDll;
  93. ZeroMemory(&sData.m_ptrWrappers, sizeof(sData.m_ptrWrappers));
  94. }
  95. }
  96. void CXTPWinThemeWrapper::SetThemeWrapperPtr(int nThemeWrapper, LPVOID lpWrapperPtr)
  97. {
  98. GetSharedData().m_ptrWrappers[nThemeWrapper] = lpWrapperPtr;
  99. }
  100. void CXTPWinThemeWrapper::CloseThemeData()
  101. {
  102. if (m_hTheme && !m_bDllDetached)
  103. {
  104. TRY_POINTER_CALL(CloseThemeData)
  105. POINTER_CALL(m_hTheme);
  106. CATCH_POINTER_CALL()
  107. }
  108. m_hTheme = NULL;
  109. }
  110. HRESULT CXTPWinThemeWrapper::DrawThemeBackground(HDC hDC, int iPartID, int iStateID, const RECT* pRect, const RECT* pClipRect)
  111. {
  112. TRY_POINTER_CALL(DrawThemeBackground);
  113. return POINTER_CALL(m_hTheme, hDC, iPartID, iStateID, pRect, pClipRect);
  114. CATCH_POINTER_CALL()
  115. return E_FAIL;
  116. }
  117. HRESULT CXTPWinThemeWrapper::DrawThemeBackgroundEx(HDC hDC, int iPartID, int iStateID, const RECT* pRect, const PDTBGOPTS pOptions)
  118. {
  119. TRY_POINTER_CALL(DrawThemeBackgroundEx)
  120. return POINTER_CALL(m_hTheme, hDC, iPartID, iStateID, pRect, pOptions);
  121. CATCH_POINTER_CALL()
  122. return E_FAIL;
  123. }
  124. HRESULT CXTPWinThemeWrapper::DrawThemeEdge(HDC hDC, int iPartID, int iStateID, const RECT* pDestRect, UINT uEdge, UINT uFlags, RECT* pContentRect)
  125. {
  126. TRY_POINTER_CALL(DrawThemeEdge)
  127. return POINTER_CALL(m_hTheme, hDC, iPartID, iStateID, pDestRect, uEdge, uFlags, pContentRect);
  128. CATCH_POINTER_CALL()
  129. return E_FAIL;
  130. }
  131. HRESULT CXTPWinThemeWrapper::DrawThemeIcon(HDC hDC, int iPartID, int iStateID, const RECT* pRect, HIMAGELIST himl, int iImageIndex)
  132. {
  133. TRY_POINTER_CALL(DrawThemeIcon)
  134. return POINTER_CALL(m_hTheme, hDC, iPartID, iStateID, pRect, himl, iImageIndex);
  135. CATCH_POINTER_CALL()
  136. return E_FAIL;
  137. }
  138. HRESULT CXTPWinThemeWrapper::DrawThemeParentBackground(HWND hWnd, HDC hDC, RECT* pRect)
  139. {
  140. TRY_POINTER_CALL(DrawThemeParentBackground)
  141. return POINTER_CALL(hWnd, hDC, pRect);
  142. CATCH_POINTER_CALL()
  143. return E_FAIL;
  144. }
  145. HRESULT CXTPWinThemeWrapper::DrawThemeText(HDC hDC, int iPartID, int iStateID, LPCWSTR pszText, int iCharCount, DWORD dwTextFlags, DWORD dwTextFlags2, const RECT* pRect)
  146. {
  147. TRY_POINTER_CALL(DrawThemeText)
  148. return POINTER_CALL(m_hTheme, hDC, iPartID, iStateID, pszText, iCharCount, dwTextFlags, dwTextFlags2, pRect);
  149. CATCH_POINTER_CALL()
  150. return E_FAIL;
  151. }
  152. HRESULT CXTPWinThemeWrapper::EnableThemeDialogTexture(HWND hWnd, DWORD dwFlags)
  153. {
  154. TRY_POINTER_CALL(EnableThemeDialogTexture)
  155. return POINTER_CALL(hWnd, dwFlags);
  156. CATCH_POINTER_CALL()
  157. return E_FAIL;
  158. }
  159. HRESULT CXTPWinThemeWrapper::EnableTheming(BOOL fEnable)
  160. {
  161. TRY_POINTER_CALL(EnableTheming)
  162. return POINTER_CALL(fEnable);
  163. CATCH_POINTER_CALL()
  164. return E_FAIL;
  165. }
  166. HRESULT CXTPWinThemeWrapper::GetCurrentThemeName(LPWSTR pszThemeFileName, int dwMaxNameChars, LPWSTR pszColorBuff, int cchMaxColorChars, LPWSTR pszSizeBuff, int cchMaxSizeChars)
  167. {
  168. ReloadLibrary();
  169. TRY_POINTER_CALL(GetCurrentThemeName)
  170. return POINTER_CALL(pszThemeFileName, dwMaxNameChars, pszColorBuff, cchMaxColorChars, pszSizeBuff, cchMaxSizeChars);
  171. CATCH_POINTER_CALL()
  172. return E_FAIL;
  173. }
  174. DWORD CXTPWinThemeWrapper::ThemeAppProperties()
  175. {
  176. TRY_POINTER_CALL(ThemeAppProperties)
  177. return POINTER_CALL();
  178. CATCH_POINTER_CALL()
  179. return 0L;
  180. }
  181. HRESULT CXTPWinThemeWrapper::GetThemeBackgroundContentRect(HDC hDC, int iPartID, int iStateID, const RECT* pBoundingRect, RECT* pContentRect)
  182. {
  183. TRY_POINTER_CALL(GetThemeBackgroundContentRect)
  184. return POINTER_CALL(m_hTheme, hDC, iPartID, iStateID, pBoundingRect, pContentRect);
  185. CATCH_POINTER_CALL()
  186. return E_FAIL;
  187. }
  188. HRESULT CXTPWinThemeWrapper::GetThemeBackgroundExtent(HDC hDC, int iPartID, int iStateID, const RECT* pContentRect, RECT* pExtentRect)
  189. {
  190. TRY_POINTER_CALL(GetThemeBackgroundExtent)
  191. return POINTER_CALL(m_hTheme, hDC, iPartID, iStateID, pContentRect, pExtentRect);
  192. CATCH_POINTER_CALL()
  193. return E_FAIL;
  194. }
  195. HRESULT CXTPWinThemeWrapper::GetThemeBackgroundRegion(HDC hDC, int iPartID, int iStateID, const RECT* pRect, HRGN* pRegion)
  196. {
  197. TRY_POINTER_CALL(GetThemeBackgroundRegion)
  198. return POINTER_CALL(m_hTheme, hDC, iPartID, iStateID, pRect, pRegion);
  199. CATCH_POINTER_CALL()
  200. return E_FAIL;
  201. }
  202. HRESULT CXTPWinThemeWrapper::GetThemeBool(int iPartID, int iStateID, int iPropID, BOOL* pfVal)
  203. {
  204. TRY_POINTER_CALL(GetThemeBool)
  205. return POINTER_CALL(m_hTheme, iPartID, iStateID, iPropID, pfVal);
  206. CATCH_POINTER_CALL()
  207. return E_FAIL;
  208. }
  209. HRESULT CXTPWinThemeWrapper::GetThemeColor(int iPartID, int iStateID, int iPropID, COLORREF* pColor)
  210. {
  211. TRY_POINTER_CALL(GetThemeColor)
  212. return POINTER_CALL(m_hTheme, iPartID, iStateID, iPropID, pColor);
  213. CATCH_POINTER_CALL()
  214. return E_FAIL;
  215. }
  216. HRESULT CXTPWinThemeWrapper::GetThemeDocumentationProperty(LPCWSTR pszThemeName, LPCWSTR pszPropertyName, LPWSTR pszValueBuff, int cchMaxValChars)
  217. {
  218. TRY_POINTER_CALL(GetThemeDocumentationProperty)
  219. return POINTER_CALL(pszThemeName, pszPropertyName, pszValueBuff, cchMaxValChars);
  220. CATCH_POINTER_CALL()
  221. return E_FAIL;
  222. }
  223. HRESULT CXTPWinThemeWrapper::GetThemeEnumValue(int iPartID, int iStateID, int iPropID, int* piVal)
  224. {
  225. TRY_POINTER_CALL(GetThemeEnumValue)
  226. return POINTER_CALL(m_hTheme, iPartID, iStateID, iPropID, piVal);
  227. CATCH_POINTER_CALL()
  228. return E_FAIL;
  229. }
  230. HRESULT CXTPWinThemeWrapper::GetThemeFilename(int iPartID, int iStateID, int iPropID, LPWSTR pszThemeFilename, int cchMaxBuffChars)
  231. {
  232. TRY_POINTER_CALL(GetThemeFilename)
  233. return POINTER_CALL(m_hTheme, iPartID, iStateID, iPropID, pszThemeFilename, cchMaxBuffChars);
  234. CATCH_POINTER_CALL()
  235. return E_FAIL;
  236. }
  237. HRESULT CXTPWinThemeWrapper::GetThemeFont(HDC hDC, int iPartID, int iStateID, int iPropID, LOGFONT* pFont)
  238. {
  239. TRY_POINTER_CALL(GetThemeFont)
  240. return POINTER_CALL(m_hTheme, hDC, iPartID, iStateID, iPropID, pFont);
  241. CATCH_POINTER_CALL()
  242. return E_FAIL;
  243. }
  244. HRESULT CXTPWinThemeWrapper::GetThemeInt(int iPartID, int iStateID, int iPropID, int* piVal)
  245. {
  246. TRY_POINTER_CALL(GetThemeInt)
  247. return POINTER_CALL(m_hTheme, iPartID, iStateID, iPropID, piVal);
  248. CATCH_POINTER_CALL()
  249. return E_FAIL;
  250. }
  251. HRESULT CXTPWinThemeWrapper::GetThemeIntList(int iPartID, int iStateID, int iPropID, INTLIST* pIntList)
  252. {
  253. TRY_POINTER_CALL(GetThemeIntList)
  254. return POINTER_CALL(m_hTheme, iPartID, iStateID, iPropID, pIntList);
  255. CATCH_POINTER_CALL()
  256. return E_FAIL;
  257. }
  258. HRESULT CXTPWinThemeWrapper::GetThemeMargins(HDC hDC, int iPartID, int iStateID, int iPropID, RECT* pRect, MARGINS* pMargins)
  259. {
  260. TRY_POINTER_CALL(GetThemeMargins)
  261. return POINTER_CALL(m_hTheme, hDC, iPartID, iStateID, iPropID, pRect, pMargins);
  262. CATCH_POINTER_CALL()
  263. return E_FAIL;
  264. }
  265. HRESULT CXTPWinThemeWrapper::GetThemeMetric(HDC hDC, int iPartID, int iStateID, int iPropID, int* piVal)
  266. {
  267. TRY_POINTER_CALL(GetThemeMetric)
  268. return POINTER_CALL(m_hTheme, hDC, iPartID, iStateID, iPropID, piVal);
  269. CATCH_POINTER_CALL()
  270. return E_FAIL;
  271. }
  272. HRESULT CXTPWinThemeWrapper::GetThemePartSize(HDC hDC, int iPartID, int iStateID, RECT* pRect, THEMESIZE eSize, SIZE* pSize)
  273. {
  274. TRY_POINTER_CALL(GetThemePartSize)
  275. return POINTER_CALL(m_hTheme, hDC, iPartID, iStateID, pRect, eSize, pSize);
  276. CATCH_POINTER_CALL()
  277. return E_FAIL;
  278. }
  279. HRESULT CXTPWinThemeWrapper::GetThemePosition(int iPartID, int iStateID, int iPropID, POINT* pPoint)
  280. {
  281. TRY_POINTER_CALL(GetThemePosition)
  282. return POINTER_CALL(m_hTheme, iPartID, iStateID, iPropID, pPoint);
  283. CATCH_POINTER_CALL()
  284. return E_FAIL;
  285. }
  286. HRESULT CXTPWinThemeWrapper::GetThemePropertyOrigin(int iPartID, int iStateID, int iPropID, PROPERTYORIGIN* pOrigin)
  287. {
  288. TRY_POINTER_CALL(GetThemePropertyOrigin)
  289. return POINTER_CALL(m_hTheme, iPartID, iStateID, iPropID, pOrigin);
  290. CATCH_POINTER_CALL()
  291. return E_FAIL;
  292. }
  293. HRESULT CXTPWinThemeWrapper::GetThemeRect(int iPartID, int iStateID, int iPropID, RECT* pRect)
  294. {
  295. TRY_POINTER_CALL(GetThemeRect)
  296. return POINTER_CALL(m_hTheme, iPartID, iStateID, iPropID, pRect);
  297. CATCH_POINTER_CALL()
  298. return E_FAIL;
  299. }
  300. HRESULT CXTPWinThemeWrapper::GetThemeString(int iPartID, int iStateID, int iPropID, LPWSTR pszBuff, int cchMaxBuffChars)
  301. {
  302. TRY_POINTER_CALL(GetThemeString)
  303. return POINTER_CALL(m_hTheme, iPartID, iStateID, iPropID, pszBuff, cchMaxBuffChars);
  304. CATCH_POINTER_CALL()
  305. return E_FAIL;
  306. }
  307. BOOL CXTPWinThemeWrapper::GetThemeSysBool(int iBoolID)
  308. {
  309. TRY_POINTER_CALL(GetThemeSysBool)
  310. return POINTER_CALL(m_hTheme, iBoolID);
  311. CATCH_POINTER_CALL()
  312. return FALSE;
  313. }
  314. COLORREF CXTPWinThemeWrapper::GetThemeSysColor(int iColorID)
  315. {
  316. TRY_POINTER_CALL(GetThemeSysColor)
  317. return POINTER_CALL(m_hTheme, iColorID);
  318. CATCH_POINTER_CALL()
  319. return (COLORREF)-1;
  320. }
  321. HBRUSH CXTPWinThemeWrapper::GetThemeSysColorBrush(int iColorID)
  322. {
  323. TRY_POINTER_CALL(GetThemeSysColorBrush)
  324. return POINTER_CALL(m_hTheme, iColorID);
  325. CATCH_POINTER_CALL()
  326. return NULL;
  327. }
  328. HRESULT CXTPWinThemeWrapper::GetThemeSysFont(int iFontID, LOGFONT* pLF)
  329. {
  330. TRY_POINTER_CALL(GetThemeSysFont)
  331. return POINTER_CALL(m_hTheme, iFontID, pLF);
  332. CATCH_POINTER_CALL()
  333. return E_FAIL;
  334. }
  335. HRESULT CXTPWinThemeWrapper::GetThemeSysInt(int iIntID, int* piValue)
  336. {
  337. TRY_POINTER_CALL(GetThemeSysInt)
  338. return POINTER_CALL(m_hTheme, iIntID, piValue);
  339. CATCH_POINTER_CALL()
  340. return E_FAIL;
  341. }
  342. int CXTPWinThemeWrapper::GetThemeSysSize(int iSizeID)
  343. {
  344. TRY_POINTER_CALL(GetThemeSysSize)
  345. return POINTER_CALL(m_hTheme, iSizeID);
  346. CATCH_POINTER_CALL()
  347. return 0;
  348. }
  349. HRESULT CXTPWinThemeWrapper::GetThemeSysString(int iStringID, LPWSTR pszStringBuff, int cchMaxStringChars)
  350. {
  351. TRY_POINTER_CALL(GetThemeSysString)
  352. return POINTER_CALL(m_hTheme, iStringID, pszStringBuff, cchMaxStringChars);
  353. CATCH_POINTER_CALL()
  354. return E_FAIL;
  355. }
  356. HRESULT CXTPWinThemeWrapper::GetThemeTextExtent(HDC hDC, int iPartID, int iStateID, LPCWSTR pszText, int iCharCount, DWORD dwTextFlags, const RECT* pBoundingRect, RECT* pExtentRect)
  357. {
  358. TRY_POINTER_CALL(GetThemeTextExtent)
  359. return POINTER_CALL(m_hTheme, hDC, iPartID, iStateID, pszText, iCharCount, dwTextFlags, pBoundingRect, pExtentRect);
  360. CATCH_POINTER_CALL()
  361. return E_FAIL;
  362. }
  363. HRESULT CXTPWinThemeWrapper::GetThemeTextMetrics(HDC hDC, int iPartID, int iStateID, TEXTMETRIC* ptm)
  364. {
  365. TRY_POINTER_CALL(GetThemeTextMetrics)
  366. return POINTER_CALL(m_hTheme, hDC, iPartID, iStateID, ptm);
  367. CATCH_POINTER_CALL()
  368. return E_FAIL;
  369. }
  370. HTHEME CXTPWinThemeWrapper::GetWindowTheme(HWND hWnd)
  371. {
  372. TRY_POINTER_CALL(GetWindowTheme)
  373. return POINTER_CALL(hWnd);
  374. CATCH_POINTER_CALL()
  375. return NULL;
  376. }
  377. HRESULT CXTPWinThemeWrapper::HitTestThemeBackground(HDC hDC, int iPartID, int iStateID, DWORD dwOptions, const RECT* pRect, HRGN hRgn, POINT ptTest, WORD* pwHitTestCode)
  378. {
  379. TRY_POINTER_CALL(HitTestThemeBackground)
  380. return POINTER_CALL(m_hTheme, hDC, iPartID, iStateID, dwOptions, pRect, hRgn, ptTest, pwHitTestCode);
  381. CATCH_POINTER_CALL()
  382. return E_FAIL;
  383. }
  384. BOOL CXTPWinThemeWrapper::IsAppThemed() const
  385. {
  386. if (!m_hTheme)
  387. return FALSE;
  388. TRY_POINTER_CALL(IsAppThemed)
  389. return POINTER_CALL();
  390. CATCH_POINTER_CALL()
  391. return FALSE;
  392. }
  393. BOOL CXTPWinThemeWrapper::IsThemeActive() const
  394. {
  395. if (m_hTheme == 0)
  396. {
  397. ReloadLibrary();
  398. }
  399. TRY_POINTER_CALL(IsThemeActive)
  400. return POINTER_CALL();
  401. CATCH_POINTER_CALL()
  402. return FALSE;
  403. }
  404. BOOL CXTPWinThemeWrapper::IsThemeBackgroundPartiallyTransparent(int iPartID, int iStateID)
  405. {
  406. TRY_POINTER_CALL(IsThemeBackgroundPartiallyTransparent)
  407. return POINTER_CALL(m_hTheme, iPartID, iStateID);
  408. CATCH_POINTER_CALL()
  409. return FALSE;
  410. }
  411. BOOL CXTPWinThemeWrapper::IsThemeDialogTextureEnabled()
  412. {
  413. TRY_POINTER_CALL(IsThemeDialogTextureEnabled)
  414. return POINTER_CALL();
  415. CATCH_POINTER_CALL()
  416. return FALSE;
  417. }
  418. BOOL CXTPWinThemeWrapper::IsThemePartDefined(int iPartID, int iStateID)
  419. {
  420. TRY_POINTER_CALL(IsThemePartDefined)
  421. return POINTER_CALL(m_hTheme, iPartID, iStateID);
  422. CATCH_POINTER_CALL()
  423. return FALSE;
  424. }
  425. void CXTPWinThemeWrapper::OpenThemeData(HWND hWnd, LPCWSTR pszClassList)
  426. {
  427. ReloadLibrary();
  428. CloseThemeData();
  429. TRY_POINTER_CALL(OpenThemeData)
  430. m_hTheme = POINTER_CALL(hWnd, pszClassList);
  431. CATCH_POINTER_CALL()
  432. }
  433. void CXTPWinThemeWrapper::SetThemeAppProperties(DWORD dwFlags)
  434. {
  435. TRY_POINTER_CALL(SetThemeAppProperties)
  436. POINTER_CALL(dwFlags);
  437. CATCH_POINTER_CALL()
  438. }
  439. HRESULT CXTPWinThemeWrapper::SetWindowTheme(HWND hWnd, LPCWSTR pszSubAppName, LPCWSTR pszSubIdList)
  440. {
  441. TRY_POINTER_CALL(SetWindowTheme)
  442. return POINTER_CALL(hWnd, pszSubAppName, pszSubIdList);
  443. CATCH_POINTER_CALL()
  444. return E_FAIL;
  445. }
  446. DWORD CXTPWinThemeWrapper::GetThemeAppProperties()
  447. {
  448. TRY_POINTER_CALL(GetThemeAppProperties)
  449. return POINTER_CALL();
  450. CATCH_POINTER_CALL()
  451. return 0;
  452. }
  453. BOOL CXTPWinThemeWrapper::ThemeDataOpen() const
  454. {
  455. return (m_hTheme != NULL);
  456. }
  457. BOOL CXTPWinThemeWrapper::IsAppThemeReady() const
  458. {
  459. // This will fail when using Windows "classic" or any non
  460. // theme mode the system themes are not available to use.
  461. if (!IsThemeActive())
  462. return FALSE;
  463. if (GetSharedData().m_hThemeDll == XTP_UXTHEME_HANDLE)
  464. return TRUE;
  465. // By loading the comctl32.dll, we can determine if the application
  466. // has a manifest file because the application will load comctl32.dll
  467. // version 6.0 (or greater).  If it does not contain a manifest file
  468. // the application will load version 5.0 or earlier.
  469. // Our application is able to display Windows XP themes.
  470. if (HIWORD(GetSharedData().m_dwComCtlVersion) > 5)
  471. return TRUE;
  472. return FALSE;
  473. }
  474. /// Vista
  475. HRESULT CXTPWinThemeWrapper::DrawThemeTextEx(HDC hDC, int iPartId, int iStateId, LPCWSTR pszText, int cchText, DWORD dwTextFlags, LPRECT pRect, const XTP_UX_DTTOPTS *pOptions)
  476. {
  477. TRY_POINTER_CALL(DrawThemeTextEx)
  478. return POINTER_CALL(m_hTheme, hDC, iPartId, iStateId, pszText, cchText, dwTextFlags, pRect, pOptions);
  479. CATCH_POINTER_CALL()
  480. return E_FAIL;
  481. }
  482. HPAINTBUFFER CXTPWinThemeWrapper::BeginBufferedPaint(HDC hdcTarget, const RECT* prcTarget, XTP_UX_BUFFERFORMAT dwFormat, XTP_UX_PAINTPARAMS *pPaintParams, HDC *phdc)
  483. {
  484. TRY_POINTER_CALL(BeginBufferedPaint)
  485. return POINTER_CALL(hdcTarget, prcTarget, dwFormat, pPaintParams, phdc);
  486. CATCH_POINTER_CALL()
  487. return NULL;
  488. }
  489. void CXTPWinThemeWrapper::EndBufferedPaint(HPAINTBUFFER hBufferedPaint, BOOL fUpdateTarget)
  490. {
  491. TRY_POINTER_CALL(EndBufferedPaint)
  492. POINTER_CALL(hBufferedPaint, fUpdateTarget);
  493. CATCH_POINTER_CALL()
  494. }
  495. //////////////////////////////////////////////////////////////////////////
  496. CXTPWinDwmWrapper::CSharedData::CSharedData()
  497. {
  498. ZeroMemory(&m_ptrWrappers, sizeof(m_ptrWrappers));
  499. m_hDwmDll = ::LoadLibrary(_T("dwmapi.dll"));
  500. }
  501. CXTPWinDwmWrapper::CSharedData& CXTPWinDwmWrapper::GetSharedData() const
  502. {
  503. static CSharedData sData;
  504. return sData;
  505. }
  506. CXTPWinDwmWrapper::CXTPWinDwmWrapper()
  507. {
  508. }
  509. CXTPWinDwmWrapper::~CXTPWinDwmWrapper()
  510. {
  511. }
  512. BOOL CXTPWinDwmWrapper::IsCompositionEnabled()
  513. {
  514. CSharedData& sData = GetSharedData();
  515. if (sData.m_hDwmDll != NULL && sData.m_ptrWrappers[xtpWrapperDwmIsCompositionEnabled] == NULL)
  516. {
  517. sData.m_ptrWrappers[xtpWrapperDwmIsCompositionEnabled] = ::GetProcAddress(
  518. sData.m_hDwmDll, xtpWrapperProcDwmIsCompositionEnabled);
  519. }
  520. PFNDwmIsCompositionEnabled ptr = (PFNDwmIsCompositionEnabled)sData.m_ptrWrappers[xtpWrapperDwmIsCompositionEnabled];
  521. if (ptr)
  522. {
  523. BOOL bEnabled = FALSE;
  524. LRESULT lResult = (*ptr)(&bEnabled);
  525. if (FAILED(lResult))
  526. return FALSE;
  527. return bEnabled;
  528. }
  529. return FALSE;
  530. }
  531. HRESULT CXTPWinDwmWrapper::DefWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *plResult)
  532. {
  533. CSharedData& sData = GetSharedData();
  534. if (sData.m_hDwmDll != NULL && sData.m_ptrWrappers[xtpWrapperDwmDefWindowProc] == NULL)
  535. {
  536. sData.m_ptrWrappers[xtpWrapperDwmDefWindowProc] = ::GetProcAddress(
  537. sData.m_hDwmDll, xtpWrapperProcDwmDefWindowProc);
  538. }
  539. PFNDwmDefWindowProc ptr = (PFNDwmDefWindowProc)sData.m_ptrWrappers[xtpWrapperDwmDefWindowProc];
  540. if (ptr)
  541. {
  542. return (*ptr)(hWnd, msg, wParam, lParam, plResult);
  543. }
  544. return E_FAIL;
  545. }
  546. HRESULT CXTPWinDwmWrapper::ExtendFrameIntoClientArea(HWND hWnd, int cxLeftWidth, int cyTopHeight, int cxRightWidth, int cyBottomHeight)
  547. {
  548. CSharedData& sData = GetSharedData();
  549. if (sData.m_hDwmDll != NULL && sData.m_ptrWrappers[xtpWrapperDwmExtendFrameIntoClientArea] == NULL)
  550. {
  551. sData.m_ptrWrappers[xtpWrapperDwmExtendFrameIntoClientArea] = ::GetProcAddress(
  552. sData.m_hDwmDll, xtpWrapperProcDwmExtendFrameIntoClientArea);
  553. }
  554. PFNDwmExtendFrameIntoClientArea ptr = (PFNDwmExtendFrameIntoClientArea)sData.m_ptrWrappers[xtpWrapperDwmExtendFrameIntoClientArea];
  555. if (ptr)
  556. {
  557. XTP_DWM_MARGINS margins;
  558. margins.cxLeftWidth = cxLeftWidth;
  559. margins.cyTopHeight = cyTopHeight;
  560. margins.cxRightWidth = cxRightWidth;
  561. margins.cyBottomHeight = cyBottomHeight;
  562. return (*ptr)(hWnd, &margins);
  563. }
  564. return E_FAIL;
  565. }
  566. void CXTPWinDwmWrapper::LogicalToPhysicalPoint(HWND hWnd, LPPOINT lpPoint)
  567. {
  568. HMODULE hModule = GetModuleHandle(_T("user32.dll"));
  569. ASSERT(hModule);
  570. if (!hModule)
  571. return;
  572. typedef void (WINAPI* PFNLOGICALTOPHYSICALPOINT)(HWND, LPPOINT);
  573. PFNLOGICALTOPHYSICALPOINT pfnLogicalToPhysicalPoint =
  574. (PFNLOGICALTOPHYSICALPOINT)GetProcAddress(hModule, "LogicalToPhysicalPoint");
  575. if (pfnLogicalToPhysicalPoint)
  576. {
  577. pfnLogicalToPhysicalPoint(hWnd, lpPoint);
  578. }
  579. }
  580. void CXTPWinDwmWrapper::SetProcessDPIAware()
  581. {
  582. HMODULE hModule = GetModuleHandle(_T("user32.dll"));
  583. ASSERT(hModule);
  584. if (!hModule)
  585. return;
  586. typedef void (WINAPI* PFNSETPROCESSDPIAWARE)();
  587. PFNSETPROCESSDPIAWARE pfnSetProcessDPIAware =
  588. (PFNSETPROCESSDPIAWARE)GetProcAddress(hModule, "SetProcessDPIAware");
  589. if (pfnSetProcessDPIAware)
  590. {
  591. pfnSetProcessDPIAware();
  592. }
  593. }