TNB Library
TnbThemeStylePartsDrawer.h
[詳解]
1#pragma once
15#include <UxTheme.h>
16#include "TnbPartsDrawable.h"
17#include "TnbDynamicFunc.h"
18
19
20
21#ifndef _TnbDOXYGEN //Document作成用シンボル
22
23#ifndef VSCLASS_BUTTON
24 // BUTTON class parts and states
25 #define VSCLASS_BUTTON L"BUTTON"
26#endif // VSCLASS_BUTTON
27
28#if ! defined(TMSCHEMA_H) && ! defined(__VSSTYLE_H__)
29
30enum BUTTONPARTS {
31 BP_PUSHBUTTON = 1,
32 BP_RADIOBUTTON = 2,
33 BP_CHECKBOX = 3,
34 BP_GROUPBOX = 4,
35 BP_USERBUTTON = 5,
36};
37
38enum PUSHBUTTONSTATES {
39 PBS_NORMAL = 1,
40 PBS_HOT = 2,
41 PBS_PRESSED = 3,
42 PBS_DISABLED = 4,
43 PBS_DEFAULTED = 5,
44};
45
46enum RADIOBUTTONSTATES {
47 RBS_UNCHECKEDNORMAL = 1,
48 RBS_UNCHECKEDHOT = 2,
49 RBS_UNCHECKEDPRESSED = 3,
50 RBS_UNCHECKEDDISABLED = 4,
51 RBS_CHECKEDNORMAL = 5,
52 RBS_CHECKEDHOT = 6,
53 RBS_CHECKEDPRESSED = 7,
54 RBS_CHECKEDDISABLED = 8,
55};
56
57enum CHECKBOXSTATES {
58 CBS_UNCHECKEDNORMAL = 1,
59 CBS_UNCHECKEDHOT = 2,
60 CBS_UNCHECKEDPRESSED = 3,
61 CBS_UNCHECKEDDISABLED = 4,
62 CBS_CHECKEDNORMAL = 5,
63 CBS_CHECKEDHOT = 6,
64 CBS_CHECKEDPRESSED = 7,
65 CBS_CHECKEDDISABLED = 8,
66 CBS_MIXEDNORMAL = 9,
67 CBS_MIXEDHOT = 10,
68 CBS_MIXEDPRESSED = 11,
69 CBS_MIXEDDISABLED = 12,
70};
71
72enum GROUPBOXSTATES {
73 GBS_NORMAL = 1,
74 GBS_DISABLED = 2,
75};
76
77#endif //TMSCHEMA_H
78
79#endif //_TnbDOXYGEN
80
81
82
83//TNB Library
84namespace TNB {
85namespace MFC {
86
87
88
89#ifndef _TnbDOXYGEN //Document作成用シンボル
90 _SELECTANY bool s_isCheckedThemeDll = false;
91#endif
92
93
94
109{
110 DEFSUPER(CStandardPartsDrawer);
112 #define _TnbTHEMEDLL_NAME "UxTheme.dll"
113 mutable HTHEME m_hTheme;
114 typedef HRESULT(WINAPI *P_DrawThemeBackground)(HTHEME, HDC, int, int, const RECT *, const RECT *);
117 bool m_CheckOpen(HDC hdc) const
118 {
119 if ( m_hTheme == NULL && IsThemeActive() )
120 {
121 m_hTheme = OpenThemeData(::WindowFromDC(hdc), VSCLASS_BUTTON);
122 }
123 return m_hTheme != NULL;
124 }
125public:
126
128 CThemeStylePartsDrawer(void) : m_hTheme(NULL)
129 {
130 if ( ! s_isCheckedThemeDll )
131 {
132 if ( ! m_bkgd.LoadFunc(_TnbTHEMEDLL_NAME, "DrawThemeBackground") )
133 {
134 s_isCheckedThemeDll = true;
135 }
136 }
137 }
138
141 {
142 ThemeChanged();
143 }
144
149 void ThemeChanged(void)
150 {
151 if ( m_hTheme != NULL )
152 {
153 CloseThemeData(m_hTheme);
154 m_hTheme = NULL;
155 }
156 }
157
168 virtual bool DrawButtonControl(HDC hdc, LPRECT _lprc, UINT uState) const
169 {
170 if ( ! m_bkgd.HasFunc() || ! m_CheckOpen(hdc) )
171 {
172 #ifdef _TnbTHEME_ClassicOriginal
173 uState &= ~DFCS_HOT;
174 #endif
175 return _super::DrawButtonControl(hdc, _lprc, uState);
176 }
177 int iPartId = -9;
178 int iStateId = -9;
179 switch ( uState & 0x001F )
180 {
181 case DFCS_BUTTONPUSH:
182 iPartId = BP_PUSHBUTTON;
183 iStateId = PBS_NORMAL;
184 break;
185 case DFCS_BUTTONCHECK:
186 iPartId = BP_CHECKBOX;
187 if ( (uState & DFCS_CHECKED) == 0 )
188 {
189 iStateId = CBS_UNCHECKEDNORMAL;
190 }
191 else
192 {
193 iStateId = CBS_CHECKEDNORMAL;
194 }
195 break;
196 case DFCS_BUTTON3STATE:
197 iPartId = BP_CHECKBOX;
198 if ( (uState & DFCS_CHECKED) == 0 )
199 {
200 iStateId = CBS_UNCHECKEDNORMAL;
201 }
202 else
203 {
204 iStateId = CBS_MIXEDNORMAL;
205 }
206 break;
207 case DFCS_BUTTONRADIO:
208 iPartId = BP_RADIOBUTTON;
209 if ( (uState & DFCS_CHECKED) == 0 )
210 {
211 iStateId = RBS_UNCHECKEDNORMAL;
212 }
213 else
214 {
215 iStateId = RBS_CHECKEDNORMAL;
216 }
217 break;
218 }
219 if ( iPartId < 0 || iStateId < 0 )
220 {
221 return false;
222 }
223 if ( (uState & DFCS_HOT) != 0 )
224 {
225 iStateId += 1;
226 }
227 else if ( (uState & DFCS_PUSHED) != 0 )
228 {
229 iStateId += 2;
230 }
231 else
232 if ( (uState & DFCS_INACTIVE) != 0 )
233 {
234 iStateId += 3;
235 }
236 //
237 switch ( uState & 0xFF )
238 {
239 case DFCS_BUTTON3STATE:
240 case DFCS_BUTTONCHECK:
241 case DFCS_BUTTONRADIO:
242 _lprc->right = _lprc->left + 13;
243 _lprc->bottom = _lprc->top + 13;
244 break;
245 }
246 if ( hdc == NULL ) { return true; }
247 HRESULT r = m_bkgd()(m_hTheme, hdc, iPartId, iStateId, _lprc, _lprc);
248 if ( r != S_OK )
249 {
250 CloseThemeData(m_hTheme);
251 m_hTheme = NULL;
252 if ( ! m_CheckOpen(hdc) )
253 {
254 #ifdef _TnbTHEME_ClassicOriginal
255 uState &= ~DFCS_HOT;
256 #endif
257 return _super::DrawButtonControl(hdc, _lprc, uState);
258 }
259 r = m_bkgd()(m_hTheme, hdc, iPartId, iStateId, _lprc, _lprc);
260 }
261 if ( r == S_OK && m_hTheme != NULL && iPartId == BP_PUSHBUTTON )
262 {
263 POINT po;
264 GetEdgeOffset(po);
265 _lprc->left += po.x;
266 _lprc->right -= po.x;
267 _lprc->top += po.y;
268 _lprc->bottom -= po.y;
269 }
270 return r == S_OK;
271 }
272
273
274 //--------------------------
275
276
282 static bool IsThemeActive(void)
283 {
284 if ( ! s_isCheckedThemeDll )
285 {
286 try
287 {
288 typedef BOOL(WINAPI *P)(void);
289 return !! CDynamicFuncT<P>(_TnbTHEMEDLL_NAME, "IsThemeActive")()();
290 }
291 catch(CNullPointerException& e)
292 {
293 ASSERT0(false, "CThemeStylePartsDrawer", "APIが見つかりません。");
294 e.OnCatch();
295 s_isCheckedThemeDll = true;
296 }
297 }
298 return false;
299 }
300
309 static HTHEME OpenThemeData(HWND hWnd, LPCWSTR pszClassList)
310 {
311 typedef HTHEME(WINAPI *P)(HWND, LPCWSTR);
312 try
313 {
314 return CDynamicFuncT<P>(_TnbTHEMEDLL_NAME, "OpenThemeData")()(hWnd, pszClassList);
315 }
316 catch(CNullPointerException& e)
317 {
318 ASSERT0(false, "CThemeStylePartsDrawer", "APIが見つかりません。");
319 e.OnCatch();
320 }
321 return NULL;
322 }
323
330 static HRESULT CloseThemeData(HTHEME hTheme)
331 {
332 try
333 {
334 typedef HRESULT(WINAPI *P)(HTHEME);
335 return CDynamicFuncT<P>(_TnbTHEMEDLL_NAME, "CloseThemeData")()(hTheme);
336 }
337 catch(CNullPointerException& e)
338 {
339 ASSERT0(false, "CThemeStylePartsDrawer", "APIが見つかりません。");
340 e.OnCatch();
341 }
342 return E_FAIL;
343 }
344
356 static HRESULT DrawThemeBackground(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, OPTIONAL const RECT *pClipRect)
357 {
358 try
359 {
360 return CDynamicFuncT<P_DrawThemeBackground>(_TnbTHEMEDLL_NAME, "DrawThemeBackground")()(hTheme, hdc, iPartId, iStateId, pRect, pClipRect);
361 }
362 catch(CNullPointerException& e)
363 {
364 ASSERT0(false, "CThemeStylePartsDrawer", "APIが見つかりません。");
365 e.OnCatch();
366 }
367 return E_FAIL;
368 }
369};
370
371
372
373}; //MFC
374}; //TNB
375
376
377
動的関数管理関係のヘッダ
パーツ描画情報のヘッダ
#define _TnbTHEMEDLL_NAME
テーマDLL名宣言
NULLポインタ例外
Definition: TnbException.h:172
void OnCatch(void) const
[表示] 内容表示
Definition: TnbException.h:69
標準WINDOWパーツ描画クラス
virtual void GetEdgeOffset(POINT &_po) const
[取得] エッジの幅、高さ.
テーマスタイルWINDOWパーツ描画クラス
~CThemeStylePartsDrawer(void)
デストラクタ
static HRESULT DrawThemeBackground(HTHEME hTheme, HDC hdc, int iPartId, int iStateId, const RECT *pRect, OPTIONAL const RECT *pClipRect)
[描画] Draws the background image defined by the visual style for the specified control part.
virtual bool DrawButtonControl(HDC hdc, LPRECT _lprc, UINT uState) const
[描画] ボタンコントロール描画.
static HRESULT CloseThemeData(HTHEME hTheme)
[処理] Closes the theme data handle.
void ThemeChanged(void)
[設定] テーマ変更.
CThemeStylePartsDrawer(void)
コンストラクタ
static bool IsThemeActive(void)
[確認] Tests if a visual style for the current application is active.
static HTHEME OpenThemeData(HWND hWnd, LPCWSTR pszClassList)
[処理] Opens the theme data for a window and its associated class.
TNB Library
Definition: TnbDoxyTitle.txt:2