TNB Library
TnbMfcFontAdjuster.h
[詳解]
1#pragma once
13#include "TnbDef.h"
14
15
16
17#ifndef __AFX_H__
18 #error
19#endif
20
21
22
23//TNB Library
24namespace TNB {
25namespace MFC {
26
27
28
54template<typename TYP = CStatic>
55class CFontAdjusterAddinT : public TYP
56{
57 DEFSUPER(TYP);
58public:
59
61 CFontAdjusterAddinT(void) : m_isSafeFontSetting(false), m_textColor(CLR_INVALID)
62 {
63 }
64
70 void ResetFontSize(void)
71 {
72 m_height = m_GetClientHeight();
73 m_Adjust();
74 }
75
80 void SetTextColor(COLORREF c = CLR_INVALID)
81 {
82 m_textColor = c;
83 }
84
89 void SetBackColor(COLORREF c = CLR_INVALID)
90 {
91 if ( m_backBrush.GetSafeHandle() != NULL )
92 {
93 m_backBrush.DeleteObject();
94 }
95 if ( IS_RGBVALUE(c) )
96 {
97 m_backBrush.CreateSolidBrush(c);
98 }
99 }
100
105 void SetLogFont(const LOGFONT& logFont)
106 {
107 m_logFont = logFont;
108 m_Adjust();
109 }
110
115 void GetLogFont(LOGFONT& _logFont) const
116 {
117 _logFont = m_logFont
118 }
119
120protected:
121
131 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
132 {
133 switch ( message )
134 {
135 case WM_SETFONT:
136 if ( ! m_isSafeFontSetting )
137 {
138 LRESULT r = _super::WindowProc(message, wParam, lParam);
139 m_Check();
140 return r;
141 }
142 break;
143 case WM_SIZE:
144 m_Adjust();
145 break;
146 }
147 return _super::WindowProc(message, wParam, lParam);
148 }
149
162 virtual BOOL OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* _pResult)
163 {
164 switch ( message )
165 {
166 case WM_CTLCOLORMSGBOX:
167 case WM_CTLCOLOREDIT:
168 case WM_CTLCOLORLISTBOX:
169 case WM_CTLCOLORBTN:
170 case WM_CTLCOLORDLG:
171 case WM_CTLCOLORSCROLLBAR:
172 case WM_CTLCOLORSTATIC:
173 if ( IS_RGBVALUE(m_textColor) )
174 {
175 HDC dc = reinterpret_cast<HDC>(wParam);
176 ::SetBkMode(dc, TRANSPARENT);
177 ::SetTextColor(dc, m_textColor);
178 if ( m_backBrush.GetSafeHandle() == NULL )
179 {
180 int f = COLOR_3DFACE;
181 if ( message == WM_CTLCOLOREDIT )
182 {
183 f = COLOR_WINDOW;
184 }
185 m_backBrush.CreateSysColorBrush(f);
186 }
187 *_pResult = reinterpret_cast<LRESULT>(m_backBrush.GetSafeHandle());
188 return true;
189 }
190 break;
191 }
192 return _super::OnChildNotify(message, wParam, lParam, _pResult);
193 }
194
200 virtual void PreSubclassWindow(void)
201 {
202 _super::PreSubclassWindow();
203 m_Check();
204 }
205
206private:
207 // クライアント高さ取得
208 int m_GetClientHeight(void)
209 {
210 CRect rc;
211 _super::GetClientRect(rc);
212 return rc.Height();
213 }
214 // 現在のサイズとフォントを確認
215 void m_Check(void)
216 {
217 m_height = m_GetClientHeight();
218 Zero(m_logFont);
219 CFont* pFont = _super::GetFont();
220 if ( pFont != NULL )
221 {
222 pFont->GetLogFont(&m_logFont);
223 }
224 m_Adjust();
225 }
226 // 調整
227 void m_Adjust(void)
228 {
229 m_isSafeFontSetting = true;
230 int height = m_GetClientHeight();
231 {
232 _super::SetFont(NULL);
233 m_font.DeleteObject();
234 }
235 LOGFONT lf = m_logFont;
236 lf.lfHeight = m_logFont.lfHeight * height / m_height;
237 m_font.CreateFontIndirect(&lf);
238 _super::SetFont(&m_font);
239 m_isSafeFontSetting = false;
240 }
241 LOGFONT m_logFont;
242 int m_height;
243 CFont m_font;
244 bool m_isSafeFontSetting;
245 COLORREF m_textColor;
246 CBrush m_backBrush;
247};
248
249
250
251}; //MFC
252}; //TNB
253
254
255
TNBライブラリの定義ヘッダ
フォント調節クラス
virtual BOOL OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT *_pResult)
[通知] for notifications from parent
void SetLogFont(const LOGFONT &logFont)
[設定] フォント属性設定.
void ResetFontSize(void)
[設定] フォントサイズリセット.
void GetLogFont(LOGFONT &_logFont) const
[取得] フォント属性取得.
void SetBackColor(COLORREF c=CLR_INVALID)
[設定] 背景色指定.
virtual void PreSubclassWindow(void)
[通知] subclassing/unsubclassing functions.
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
[通知] for processing Windows messages.
void SetTextColor(COLORREF c=CLR_INVALID)
[設定] 文字色指定.
CFontAdjusterAddinT(void)
コンストラクタ
void Zero(V &value)
[設定] ゼロクリア.
Definition: TnbDef.h:399
TNB Library
Definition: TnbDoxyTitle.txt:2