1
by Sérgio Benjamim
1.3.0 source (from ppsspp_1.3.0-r160.p5.l1762.a165.t83~56~ubuntu16.04.1.tar.xz). |
1 |
// Windows Template Library - WTL version 7.0
|
2 |
// Copyright (C) 1997-2002 Microsoft Corporation
|
|
3 |
// All rights reserved.
|
|
4 |
//
|
|
5 |
// This file is a part of the Windows Template Library.
|
|
6 |
// The code and information is provided "as-is" without
|
|
7 |
// warranty of any kind, either expressed or implied.
|
|
8 |
||
9 |
||
10 |
#pragma once
|
|
11 |
||
12 |
#include <tchar.h> |
|
13 |
//#include <tmschema.h>
|
|
14 |
#include <uxtheme.h> |
|
15 |
#pragma comment(lib, "uxtheme.lib")
|
|
16 |
||
17 |
// Note: To create an application that also runs on older versions of Windows,
|
|
18 |
// use delay load of uxtheme.dll and ensure that no calls to the Theme API are
|
|
19 |
// made if theming is not supported. It is enough to check if m_hTheme is NULL.
|
|
20 |
// Example:
|
|
21 |
// if(m_hTheme != NULL)
|
|
22 |
// {
|
|
23 |
// DrawThemeBackground(dc, BP_PUSHBUTTON, PBS_NORMAL, &rect, NULL);
|
|
24 |
// DrawThemeText(dc, BP_PUSHBUTTON, PBS_NORMAL, L"Button", -1, DT_SINGLELINE | DT_CENTER | DT_VCENTER, 0, &rect);
|
|
25 |
// }
|
|
26 |
// else
|
|
27 |
// {
|
|
28 |
// dc.DrawFrameControl(&rect, DFC_BUTTON, DFCS_BUTTONPUSH);
|
|
29 |
// dc.DrawText(_T("Button"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER);
|
|
30 |
// }
|
|
31 |
//
|
|
32 |
// Delay load is NOT AUTOMATIC for VC++ 7, you have to link to delayimp.lib,
|
|
33 |
// and add uxtheme.dll in the Linker.Input.Delay Loaded DLLs section of the
|
|
34 |
// project properties.
|
|
35 |
#if (_MSC_VER < 1300) && !defined(_WTL_NO_THEME_DELAYLOAD)
|
|
36 |
#pragma comment(lib, "delayimp.lib")
|
|
37 |
#pragma comment(linker, "/delayload:uxtheme.dll")
|
|
38 |
#endif //(_MSC_VER < 1300) && !defined(_WTL_NO_THEME_DELAYLOAD) |
|
39 |
||
40 |
||
41 |
// Classes in this file
|
|
42 |
//
|
|
43 |
// CTheme
|
|
44 |
// CThemeImpl<T, TBase>
|
|
45 |
||
46 |
||
47 |
namespace WTL |
|
48 |
{
|
|
49 |
||
50 |
// CTheme - wrapper for theme handle
|
|
51 |
||
52 |
class CTheme |
|
53 |
{
|
|
54 |
public: |
|
55 |
// Data members
|
|
56 |
HTHEME m_hTheme; |
|
57 |
static int m_nIsThemingSupported; |
|
58 |
||
59 |
// Constructor
|
|
60 |
CTheme() : m_hTheme(NULL) |
|
61 |
{
|
|
62 |
IsThemingSupported(); |
|
63 |
}
|
|
64 |
||
65 |
// Operators and helpers
|
|
66 |
bool IsThemeNull() const |
|
67 |
{
|
|
68 |
return (m_hTheme == NULL); |
|
69 |
}
|
|
70 |
||
71 |
CTheme& operator =(HTHEME hTheme) |
|
72 |
{
|
|
73 |
m_hTheme = hTheme; |
|
74 |
return *this; |
|
75 |
}
|
|
76 |
||
77 |
operator HTHEME() const |
|
78 |
{
|
|
79 |
return m_hTheme; |
|
80 |
}
|
|
81 |
||
82 |
void Attach(HTHEME hTheme) |
|
83 |
{
|
|
84 |
m_hTheme = hTheme; |
|
85 |
}
|
|
86 |
||
87 |
HTHEME Detach() |
|
88 |
{
|
|
89 |
HTHEME hTheme = m_hTheme; |
|
90 |
m_hTheme = NULL; |
|
91 |
return hTheme; |
|
92 |
}
|
|
93 |
||
94 |
// Theme support helper
|
|
95 |
static bool IsThemingSupported() |
|
96 |
{
|
|
97 |
if(m_nIsThemingSupported == -1) |
|
98 |
{
|
|
99 |
// ::EnterCriticalSection(&_Module.m_csStaticDataInit);
|
|
100 |
if(m_nIsThemingSupported == -1) |
|
101 |
{
|
|
102 |
HMODULE hThemeDLL = ::LoadLibrary(_T("uxtheme.dll")); |
|
103 |
m_nIsThemingSupported = (hThemeDLL != NULL) ? 1 : 0; |
|
104 |
if(hThemeDLL != NULL) |
|
105 |
::FreeLibrary(hThemeDLL); |
|
106 |
}
|
|
107 |
// ::LeaveCriticalSection(&_Module.m_csStaticDataInit);
|
|
108 |
}
|
|
109 |
||
110 |
//ATLASSERT(m_nIsThemingSupported != -1);
|
|
111 |
return (m_nIsThemingSupported == 1); |
|
112 |
}
|
|
113 |
||
114 |
// Operations and theme properties
|
|
115 |
HTHEME OpenThemeData(HWND hWnd, LPCWSTR pszClassList) |
|
116 |
{
|
|
117 |
if(!IsThemingSupported()) |
|
118 |
return NULL; |
|
119 |
||
120 |
//ATLASSERT(m_hTheme == NULL);
|
|
121 |
m_hTheme = ::OpenThemeData(hWnd, pszClassList); |
|
122 |
return m_hTheme; |
|
123 |
}
|
|
124 |
||
125 |
HRESULT CloseThemeData() |
|
126 |
{
|
|
127 |
HRESULT hRet = S_FALSE; |
|
128 |
if(m_hTheme != NULL) |
|
129 |
{
|
|
130 |
hRet = ::CloseThemeData(m_hTheme); |
|
131 |
if(SUCCEEDED(hRet)) |
|
132 |
m_hTheme = NULL; |
|
133 |
}
|
|
134 |
return hRet; |
|
135 |
}
|
|
136 |
||
137 |
HRESULT DrawThemeBackground(HDC hDC, int nPartID, int nStateID, LPCRECT pRect, LPCRECT pClipRect = NULL) |
|
138 |
{
|
|
139 |
return ::DrawThemeBackground(m_hTheme, hDC, nPartID, nStateID, pRect, pClipRect); |
|
140 |
}
|
|
141 |
||
142 |
HRESULT DrawThemeText(HDC hDC, int nPartID, int nStateID, LPCWSTR pszText, int nCharCount, DWORD dwTextFlags, DWORD dwTextFlags2, LPCRECT pRect) |
|
143 |
{
|
|
144 |
return ::DrawThemeText(m_hTheme, hDC, nPartID, nStateID, pszText, nCharCount, dwTextFlags, dwTextFlags2, pRect); |
|
145 |
}
|
|
146 |
||
147 |
HRESULT GetThemeBackgroundContentRect(HDC hDC, int nPartID, int nStateID, LPCRECT pBoundingRect, LPRECT pContentRect) const |
|
148 |
{
|
|
149 |
return ::GetThemeBackgroundContentRect(m_hTheme, hDC, nPartID, nStateID, pBoundingRect, pContentRect); |
|
150 |
}
|
|
151 |
||
152 |
HRESULT GetThemeBackgroundExtent(HDC hDC, int nPartID, int nStateID, LPCRECT pContentRect, LPRECT pExtentRect) const |
|
153 |
{
|
|
154 |
return ::GetThemeBackgroundExtent(m_hTheme, hDC, nPartID, nStateID, pContentRect, pExtentRect); |
|
155 |
}
|
|
156 |
||
157 |
HRESULT GetThemePartSize(HDC hDC, int nPartID, int nStateID, LPRECT pRect, enum THEMESIZE eSize, LPSIZE pSize) const |
|
158 |
{
|
|
159 |
//ATLASSERT(m_hTheme != NULL);
|
|
160 |
return ::GetThemePartSize(m_hTheme, hDC, nPartID, nStateID, pRect, eSize, pSize); |
|
161 |
}
|
|
162 |
||
163 |
HRESULT GetThemeTextExtent(HDC hDC, int nPartID, int nStateID, LPCWSTR pszText, int nCharCount, DWORD dwTextFlags, LPCRECT pBoundingRect, LPRECT pExtentRect) const |
|
164 |
{
|
|
165 |
//ATLASSERT(m_hTheme != NULL);
|
|
166 |
return ::GetThemeTextExtent(m_hTheme, hDC, nPartID, nStateID, pszText, nCharCount, dwTextFlags, pBoundingRect, pExtentRect); |
|
167 |
}
|
|
168 |
#undef UNICODE
|
|
169 |
// HRESULT GetThemeTextMetrics(HDC hDC, int nPartID, int nStateID, PTEXTMETRIC pTextMetric) const
|
|
170 |
// {
|
|
171 |
//ATLASSERT(m_hTheme != NULL);
|
|
172 |
// return ::GetThemeTextMetrics(m_hTheme, hDC, nPartID, nStateID, pTextMetric);
|
|
173 |
// }
|
|
174 |
||
175 |
HRESULT GetThemeBackgroundRegion(HDC hDC, int nPartID, int nStateID, LPCRECT pRect, HRGN* pRegion) const |
|
176 |
{
|
|
177 |
//ATLASSERT(m_hTheme != NULL);
|
|
178 |
return ::GetThemeBackgroundRegion(m_hTheme, hDC, nPartID, nStateID, pRect, pRegion); |
|
179 |
}
|
|
180 |
||
181 |
HRESULT HitTestThemeBackground(HDC hDC, int nPartID, int nStateID, DWORD dwOptions, LPCRECT pRect, HRGN hrgn, POINT ptTest, WORD* pwHitTestCode) const |
|
182 |
{
|
|
183 |
//ATLASSERT(m_hTheme != NULL);
|
|
184 |
return ::HitTestThemeBackground(m_hTheme, hDC, nPartID, nStateID, dwOptions, pRect, hrgn, ptTest, pwHitTestCode); |
|
185 |
}
|
|
186 |
||
187 |
HRESULT DrawThemeEdge(HDC hDC, int nPartID, int nStateID, LPCRECT pDestRect, UINT uEdge, UINT uFlags, LPRECT pContentRect = NULL) |
|
188 |
{
|
|
189 |
//ATLASSERT(m_hTheme != NULL);
|
|
190 |
return ::DrawThemeEdge(m_hTheme, hDC, nPartID, nStateID, pDestRect, uEdge, uFlags, pContentRect); |
|
191 |
}
|
|
192 |
||
193 |
HRESULT DrawThemeIcon(HDC hDC, int nPartID, int nStateID, LPCRECT pRect, HIMAGELIST himl, int nImageIndex) |
|
194 |
{
|
|
195 |
//ATLASSERT(m_hTheme != NULL);
|
|
196 |
return ::DrawThemeIcon(m_hTheme, hDC, nPartID, nStateID, pRect, himl, nImageIndex); |
|
197 |
}
|
|
198 |
||
199 |
BOOL IsThemePartDefined(int nPartID, int nStateID) const |
|
200 |
{
|
|
201 |
//ATLASSERT(m_hTheme != NULL);
|
|
202 |
return ::IsThemePartDefined(m_hTheme, nPartID, nStateID); |
|
203 |
}
|
|
204 |
||
205 |
BOOL IsThemeBackgroundPartiallyTransparent(int nPartID, int nStateID) const |
|
206 |
{
|
|
207 |
//ATLASSERT(m_hTheme != NULL);
|
|
208 |
return ::IsThemeBackgroundPartiallyTransparent(m_hTheme, nPartID, nStateID); |
|
209 |
}
|
|
210 |
||
211 |
HRESULT GetThemeColor(int nPartID, int nStateID, int nPropID, COLORREF* pColor) const |
|
212 |
{
|
|
213 |
//ATLASSERT(m_hTheme != NULL);
|
|
214 |
return ::GetThemeColor(m_hTheme, nPartID, nStateID, nPropID, pColor); |
|
215 |
}
|
|
216 |
||
217 |
HRESULT GetThemeMetric(HDC hDC, int nPartID, int nStateID, int nPropID, int* pnVal) const |
|
218 |
{
|
|
219 |
//ATLASSERT(m_hTheme != NULL);
|
|
220 |
return ::GetThemeMetric(m_hTheme, hDC, nPartID, nStateID, nPropID, pnVal); |
|
221 |
}
|
|
222 |
||
223 |
HRESULT GetThemeString(int nPartID, int nStateID, int nPropID, LPWSTR pszBuff, int cchMaxBuffChars) const |
|
224 |
{
|
|
225 |
//ATLASSERT(m_hTheme != NULL);
|
|
226 |
return ::GetThemeString(m_hTheme, nPartID, nStateID, nPropID, pszBuff, cchMaxBuffChars); |
|
227 |
}
|
|
228 |
||
229 |
HRESULT GetThemeBool(int nPartID, int nStateID, int nPropID, BOOL* pfVal) const |
|
230 |
{
|
|
231 |
//ATLASSERT(m_hTheme != NULL);
|
|
232 |
return ::GetThemeBool(m_hTheme, nPartID, nStateID, nPropID, pfVal); |
|
233 |
}
|
|
234 |
||
235 |
HRESULT GetThemeInt(int nPartID, int nStateID, int nPropID, int* pnVal) const |
|
236 |
{
|
|
237 |
//ATLASSERT(m_hTheme != NULL);
|
|
238 |
return ::GetThemeInt(m_hTheme, nPartID, nStateID, nPropID, pnVal); |
|
239 |
}
|
|
240 |
||
241 |
HRESULT GetThemeEnumValue(int nPartID, int nStateID, int nPropID, int* pnVal) const |
|
242 |
{
|
|
243 |
//ATLASSERT(m_hTheme != NULL);
|
|
244 |
return ::GetThemeEnumValue(m_hTheme, nPartID, nStateID, nPropID, pnVal); |
|
245 |
}
|
|
246 |
||
247 |
HRESULT GetThemePosition(int nPartID, int nStateID, int nPropID, LPPOINT pPoint) const |
|
248 |
{
|
|
249 |
//ATLASSERT(m_hTheme != NULL);
|
|
250 |
return ::GetThemePosition(m_hTheme, nPartID, nStateID, nPropID, pPoint); |
|
251 |
}
|
|
252 |
||
253 |
// HRESULT GetThemeFont(int nPartID, HDC hDC, int nStateID, int nPropID, LOGFONT* pFont) const
|
|
254 |
// {
|
|
255 |
// //ATLASSERT(m_hTheme != NULL);
|
|
256 |
// return ::GetThemeFont(m_hTheme, hDC, nPartID, nStateID, nPropID, pFont);
|
|
257 |
// }
|
|
258 |
||
259 |
HRESULT GetThemeRect(int nPartID, int nStateID, int nPropID, LPRECT pRect) const |
|
260 |
{
|
|
261 |
//ATLASSERT(m_hTheme != NULL);
|
|
262 |
return ::GetThemeRect(m_hTheme, nPartID, nStateID, nPropID, pRect); |
|
263 |
}
|
|
264 |
||
265 |
HRESULT GetThemeMargins(HDC hDC, int nPartID, int nStateID, int nPropID, LPRECT pRect, PMARGINS pMargins) const |
|
266 |
{
|
|
267 |
//ATLASSERT(m_hTheme != NULL);
|
|
268 |
return ::GetThemeMargins(m_hTheme, hDC, nPartID, nStateID, nPropID, pRect, pMargins); |
|
269 |
}
|
|
270 |
||
271 |
HRESULT GetThemeIntList(int nPartID, int nStateID, int nPropID, INTLIST* pIntList) const |
|
272 |
{
|
|
273 |
//ATLASSERT(m_hTheme != NULL);
|
|
274 |
return ::GetThemeIntList(m_hTheme, nPartID, nStateID, nPropID, pIntList); |
|
275 |
}
|
|
276 |
||
277 |
HRESULT GetThemePropertyOrigin(int nPartID, int nStateID, int nPropID, enum PROPERTYORIGIN* pOrigin) const |
|
278 |
{
|
|
279 |
//ATLASSERT(m_hTheme != NULL);
|
|
280 |
return ::GetThemePropertyOrigin(m_hTheme, nPartID, nStateID, nPropID, pOrigin); |
|
281 |
}
|
|
282 |
||
283 |
HRESULT GetThemeFilename(int nPartID, int nStateID, int nPropID, LPWSTR pszThemeFileName, int cchMaxBuffChars) const |
|
284 |
{
|
|
285 |
//ATLASSERT(m_hTheme != NULL);
|
|
286 |
return ::GetThemeFilename(m_hTheme, nPartID, nStateID, nPropID, pszThemeFileName, cchMaxBuffChars); |
|
287 |
}
|
|
288 |
||
289 |
COLORREF GetThemeSysColor(int nColorID) const |
|
290 |
{
|
|
291 |
//ATLASSERT(m_hTheme != NULL);
|
|
292 |
return ::GetThemeSysColor(m_hTheme, nColorID); |
|
293 |
}
|
|
294 |
||
295 |
HBRUSH GetThemeSysColorBrush(int nColorID) const |
|
296 |
{
|
|
297 |
//ATLASSERT(m_hTheme != NULL);
|
|
298 |
return ::GetThemeSysColorBrush(m_hTheme, nColorID); |
|
299 |
}
|
|
300 |
||
301 |
int GetThemeSysSize(int nSizeID) const |
|
302 |
{
|
|
303 |
//ATLASSERT(m_hTheme != NULL);
|
|
304 |
return ::GetThemeSysSize(m_hTheme, nSizeID); |
|
305 |
}
|
|
306 |
||
307 |
BOOL GetThemeSysBool(int nBoolID) const |
|
308 |
{
|
|
309 |
//ATLASSERT(m_hTheme != NULL);
|
|
310 |
return ::GetThemeSysBool(m_hTheme, nBoolID); |
|
311 |
}
|
|
312 |
||
313 |
// HRESULT GetThemeSysFont(int nFontID, LOGFONT* plf) const
|
|
314 |
// {
|
|
315 |
//ATLASSERT(m_hTheme != NULL);
|
|
316 |
// return ::GetThemeSysFont(m_hTheme, nFontID, plf);
|
|
317 |
// }
|
|
318 |
||
319 |
HRESULT GetThemeSysString(int nStringID, LPWSTR pszStringBuff, int cchMaxStringChars) const |
|
320 |
{
|
|
321 |
//ATLASSERT(m_hTheme != NULL);
|
|
322 |
return ::GetThemeSysString(m_hTheme, nStringID, pszStringBuff, cchMaxStringChars); |
|
323 |
}
|
|
324 |
||
325 |
HRESULT GetThemeSysInt(int nIntID, int* pnValue) const |
|
326 |
{
|
|
327 |
//ATLASSERT(m_hTheme != NULL);
|
|
328 |
return ::GetThemeSysInt(m_hTheme, nIntID, pnValue); |
|
329 |
}
|
|
330 |
};
|
|
331 |
||
332 |
__declspec(selectany) int CTheme::m_nIsThemingSupported = -1; |
|
333 |
||
334 |
||
335 |
// CThemeImpl - theme support implementation
|
|
336 |
||
337 |
// Derive from this class to implement window with theme support.
|
|
338 |
// Example:
|
|
339 |
// class CMyThemeWindow : public CWindowImpl<CMyThemeWindow>, public CThemeImpl<CMyThemeWindow>
|
|
340 |
// {
|
|
341 |
// ...
|
|
342 |
// BEGIN_MSG_MAP(CMyThemeWindow)
|
|
343 |
// CHAIN_MSG_MAP(CThemeImpl<CMyThemeWindow>)
|
|
344 |
// ...
|
|
345 |
// END_MSG_MAP()
|
|
346 |
// ...
|
|
347 |
// };
|
|
348 |
//
|
|
349 |
// If you set theme class list, the class will automaticaly open/close/reopen theme data.
|
|
350 |
||
351 |
||
352 |
// Helper for drawing theme client edge
|
|
353 |
#if 0
|
|
354 |
inline bool AtlDrawThemeClientEdge(HTHEME hTheme, HWND hWnd, HRGN hRgnUpdate = NULL, HBRUSH hBrush = NULL, int nPartID = 0, int nStateID = 0)
|
|
355 |
{
|
|
356 |
//ATLASSERT(hTheme != NULL);
|
|
357 |
//ATLASSERT(::IsWindow(hWnd));
|
|
358 |
||
359 |
CWindowDC dc(hWnd);
|
|
360 |
if(dc.IsNull())
|
|
361 |
return false;
|
|
362 |
||
363 |
// Get border size
|
|
364 |
int cxBorder = GetSystemMetrics(SM_CXBORDER);
|
|
365 |
int cyBorder = GetSystemMetrics(SM_CYBORDER);
|
|
366 |
if(SUCCEEDED(::GetThemeInt(hTheme, nPartID, nStateID, TMT_SIZINGBORDERWIDTH, &cxBorder)))
|
|
367 |
cyBorder = cxBorder;
|
|
368 |
||
369 |
RECT rect;
|
|
370 |
::GetWindowRect(hWnd, &rect);
|
|
371 |
||
372 |
// Remove the client edge from the update region
|
|
373 |
int cxEdge = GetSystemMetrics(SM_CXEDGE);
|
|
374 |
int cyEdge = GetSystemMetrics(SM_CYEDGE);
|
|
375 |
::InflateRect(&rect, -cxEdge, -cyEdge);
|
|
376 |
CRgn rgn;
|
|
377 |
rgn.CreateRectRgnIndirect(&rect);
|
|
378 |
if(rgn.IsNull())
|
|
379 |
return false;
|
|
380 |
||
381 |
if(hRgnUpdate != NULL)
|
|
382 |
rgn.CombineRgn(hRgnUpdate, rgn, RGN_AND);
|
|
383 |
||
384 |
::OffsetRect(&rect, -rect.left, -rect.top);
|
|
385 |
||
386 |
::OffsetRect(&rect, cxEdge, cyEdge);
|
|
387 |
dc.ExcludeClipRect(&rect);
|
|
388 |
::InflateRect(&rect, cxEdge, cyEdge);
|
|
389 |
||
390 |
::DrawThemeBackground(hTheme, dc, nPartID, nStateID, &rect, NULL);
|
|
391 |
||
392 |
// Use background brush too, since theme border might not cover everything
|
|
393 |
if(cxBorder < cxEdge && cyBorder < cyEdge)
|
|
394 |
{
|
|
395 |
if(hBrush == NULL)
|
|
396 |
// need conditional code because types don't match in winuser.h
|
|
397 |
#ifdef _WIN64
|
|
398 |
hBrush = (HBRUSH)::GetClassLongPtr(hWnd, GCLP_HBRBACKGROUND);
|
|
399 |
#else
|
|
400 |
hBrush = (HBRUSH)UlongToPtr(::GetClassLongPtr(hWnd, GCLP_HBRBACKGROUND));
|
|
401 |
#endif
|
|
402 |
||
403 |
::InflateRect(&rect, cxBorder - cxEdge, cyBorder - cyEdge); |
|
404 |
dc.FillRect(&rect, hBrush); |
|
405 |
}
|
|
406 |
||
407 |
::DefWindowProc(hWnd, WM_NCPAINT, (WPARAM)rgn.m_hRgn, 0L); |
|
408 |
||
409 |
return true; |
|
410 |
}
|
|
411 |
||
412 |
||
413 |
// Theme extended styles
|
|
414 |
#define THEME_EX_3DCLIENTEDGE 0x00000001
|
|
415 |
#define THEME_EX_THEMECLIENTEDGE 0x00000002
|
|
416 |
||
417 |
template <class T, class TBase = CTheme> |
|
418 |
class CThemeImpl : public TBase |
|
419 |
{
|
|
420 |
public: |
|
421 |
// Data members
|
|
422 |
LPWSTR m_lpstrThemeClassList; |
|
423 |
DWORD m_dwExtendedStyle; // theme specific extended styles |
|
424 |
||
425 |
// Constructor & destructor
|
|
426 |
CThemeImpl() : m_lpstrThemeClassList(NULL), m_dwExtendedStyle(0) |
|
427 |
{ } |
|
428 |
||
429 |
~CThemeImpl() |
|
430 |
{
|
|
431 |
delete m_lpstrThemeClassList; |
|
432 |
}
|
|
433 |
||
434 |
// Attributes
|
|
435 |
bool SetThemeClassList(LPCWSTR lpstrThemeClassList) |
|
436 |
{
|
|
437 |
if(m_lpstrThemeClassList != NULL) |
|
438 |
{
|
|
439 |
delete m_lpstrThemeClassList; |
|
440 |
m_lpstrThemeClassList = NULL; |
|
441 |
}
|
|
442 |
||
443 |
if(lpstrThemeClassList == NULL) |
|
444 |
return true; |
|
445 |
||
446 |
int cchLen = lstrlenW(lpstrThemeClassList) + 1; |
|
447 |
ATLTRY(m_lpstrThemeClassList = new WCHAR[cchLen]); |
|
448 |
if(m_lpstrThemeClassList == NULL) |
|
449 |
return false; |
|
450 |
||
451 |
bool bRet = (lstrcpyW(m_lpstrThemeClassList, lpstrThemeClassList) != NULL); |
|
452 |
if(!bRet) |
|
453 |
{
|
|
454 |
delete m_lpstrThemeClassList; |
|
455 |
m_lpstrThemeClassList = NULL; |
|
456 |
}
|
|
457 |
return bRet; |
|
458 |
}
|
|
459 |
||
460 |
bool GetThemeClassList(LPWSTR lpstrThemeClassList, int cchListBuffer) const |
|
461 |
{
|
|
462 |
int cchLen = lstrlenW(m_lpstrThemeClassList) + 1; |
|
463 |
if(cchListBuffer < cchLen) |
|
464 |
return false; |
|
465 |
||
466 |
return (lstrcpyW(lpstrThemeClassList, m_lpstrThemeClassList) != NULL); |
|
467 |
}
|
|
468 |
||
469 |
LPCWSTR GetThemeClassList() const |
|
470 |
{
|
|
471 |
return m_lpstrThemeClassList; |
|
472 |
}
|
|
473 |
||
474 |
DWORD SetThemeExtendedStyle(DWORD dwExtendedStyle, DWORD dwMask = 0) |
|
475 |
{
|
|
476 |
DWORD dwPrevStyle = m_dwExtendedStyle; |
|
477 |
if(dwMask == 0) |
|
478 |
m_dwExtendedStyle = dwExtendedStyle; |
|
479 |
else
|
|
480 |
m_dwExtendedStyle = (m_dwExtendedStyle & ~dwMask) | (dwExtendedStyle & dwMask); |
|
481 |
return dwPrevStyle; |
|
482 |
}
|
|
483 |
||
484 |
DWORD GetThemeExtendedStyle() const |
|
485 |
{
|
|
486 |
return m_dwExtendedStyle; |
|
487 |
}
|
|
488 |
||
489 |
// Operations
|
|
490 |
HTHEME OpenThemeData() |
|
491 |
{
|
|
492 |
T* pT = static_cast<T*>(this); |
|
493 |
//ATLASSERT(::IsWindow(pT->m_hWnd));
|
|
494 |
//ATLASSERT(m_lpstrThemeClassList != NULL);
|
|
495 |
if(m_lpstrThemeClassList == NULL) |
|
496 |
return NULL; |
|
497 |
CloseThemeData(); |
|
498 |
return TBase::OpenThemeData(pT->m_hWnd, m_lpstrThemeClassList); |
|
499 |
}
|
|
500 |
||
501 |
HTHEME OpenThemeData(LPCWSTR pszClassList) |
|
502 |
{
|
|
503 |
if(!SetThemeClassList(pszClassList)) |
|
504 |
return NULL; |
|
505 |
return OpenThemeData(); |
|
506 |
}
|
|
507 |
||
508 |
HRESULT SetWindowTheme(LPCWSTR pszSubAppName, LPCWSTR pszSubIDList) |
|
509 |
{
|
|
510 |
if(!IsThemingSupported()) |
|
511 |
return S_FALSE; |
|
512 |
||
513 |
T* pT = static_cast<T*>(this); |
|
514 |
//ATLASSERT(::IsWindow(pT->m_hWnd));
|
|
515 |
return ::SetWindowTheme(pT->m_hWnd, pszSubAppName, pszSubIDList); |
|
516 |
}
|
|
517 |
||
518 |
HTHEME GetWindowTheme() const |
|
519 |
{
|
|
520 |
if(!IsThemingSupported()) |
|
521 |
return NULL; |
|
522 |
||
523 |
const T* pT = static_cast<const T*>(this); |
|
524 |
//ATLASSERT(::IsWindow(pT->m_hWnd));
|
|
525 |
return ::GetWindowTheme(pT->m_hWnd); |
|
526 |
}
|
|
527 |
||
528 |
HRESULT EnableThemeDialogTexture(BOOL bEnable) |
|
529 |
{
|
|
530 |
if(!IsThemingSupported()) |
|
531 |
return S_FALSE; |
|
532 |
||
533 |
T* pT = static_cast<T*>(this); |
|
534 |
//ATLASSERT(::IsWindow(pT->m_hWnd));
|
|
535 |
return ::EnableThemeDialogTexture(pT->m_hWnd, bEnable); |
|
536 |
}
|
|
537 |
||
538 |
BOOL IsThemeDialogTextureEnabled() const |
|
539 |
{
|
|
540 |
if(!IsThemingSupported()) |
|
541 |
return FALSE; |
|
542 |
||
543 |
const T* pT = static_cast<const T*>(this); |
|
544 |
//ATLASSERT(::IsWindow(pT->m_hWnd));
|
|
545 |
return ::IsThemeDialogTextureEnabled(pT->m_hWnd); |
|
546 |
}
|
|
547 |
||
548 |
HRESULT DrawThemeParentBackground(HDC hDC, LPRECT pRect = NULL) |
|
549 |
{
|
|
550 |
if(!IsThemingSupported()) |
|
551 |
return S_FALSE; |
|
552 |
||
553 |
T* pT = static_cast<T*>(this); |
|
554 |
//ATLASSERT(::IsWindow(pT->m_hWnd));
|
|
555 |
return ::DrawThemeParentBackground(pT->m_hWnd, hDC, pRect); |
|
556 |
}
|
|
557 |
||
558 |
// Message map and handlers
|
|
559 |
// Note: If you handle any of these messages in your derived class,
|
|
560 |
// it is better to put CHAIN_MSG_MAP at the start of your message map.
|
|
561 |
BEGIN_MSG_MAP(CThemeImpl) |
|
562 |
MESSAGE_HANDLER(WM_CREATE, OnCreate) |
|
563 |
MESSAGE_HANDLER(WM_DESTROY, OnDestroy) |
|
564 |
MESSAGE_HANDLER(WM_THEMECHANGED, OnThemeChanged) |
|
565 |
MESSAGE_HANDLER(WM_NCPAINT, OnNcPaint) |
|
566 |
END_MSG_MAP() |
|
567 |
||
568 |
LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) |
|
569 |
{
|
|
570 |
if(m_lpstrThemeClassList != NULL) |
|
571 |
OpenThemeData(); |
|
572 |
bHandled = FALSE; |
|
573 |
return 1; |
|
574 |
}
|
|
575 |
||
576 |
LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled) |
|
577 |
{
|
|
578 |
CloseThemeData(); |
|
579 |
bHandled = FALSE; |
|
580 |
return 1; |
|
581 |
}
|
|
582 |
||
583 |
LRESULT OnThemeChanged(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled) |
|
584 |
{
|
|
585 |
CloseThemeData(); |
|
586 |
if(m_lpstrThemeClassList != NULL) |
|
587 |
OpenThemeData(); |
|
588 |
bHandled = FALSE; |
|
589 |
return 1; |
|
590 |
}
|
|
591 |
||
592 |
LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) |
|
593 |
{
|
|
594 |
T* pT = static_cast<T*>(this); |
|
595 |
//ATLASSERT(::IsWindow(pT->m_hWnd));
|
|
596 |
LRESULT lRet = 0; |
|
597 |
bHandled = FALSE; |
|
598 |
if(IsThemingSupported() && ((pT->GetExStyle() & WS_EX_CLIENTEDGE) != 0)) |
|
599 |
{
|
|
600 |
if((m_dwExtendedStyle & THEME_EX_3DCLIENTEDGE) != 0) |
|
601 |
{
|
|
602 |
lRet = ::DefWindowProc(pT->m_hWnd, uMsg, wParam, lParam); |
|
603 |
bHandled = TRUE; |
|
604 |
}
|
|
605 |
else if((m_hTheme != NULL) && ((m_dwExtendedStyle & THEME_EX_THEMECLIENTEDGE) != 0)) |
|
606 |
{
|
|
607 |
HRGN hRgn = (wParam != 1) ? (HRGN)wParam : NULL; |
|
608 |
if(pT->DrawThemeClientEdge(hRgn)) |
|
609 |
bHandled = TRUE; |
|
610 |
}
|
|
611 |
}
|
|
612 |
return lRet; |
|
613 |
}
|
|
614 |
||
615 |
// Drawing helper
|
|
616 |
bool DrawThemeClientEdge(HRGN hRgnUpdate) |
|
617 |
{
|
|
618 |
T* pT = static_cast<T*>(this); |
|
619 |
return AtlDrawThemeClientEdge(m_hTheme, pT->m_hWnd, hRgnUpdate, NULL, 0, 0); |
|
620 |
}
|
|
621 |
};
|
|
622 |
||
623 |
#endif
|
|
624 |
}; //namespace WTL |
|
625 |