TNB Library
TnbDcSelectAssistant.h
[詳解]
1#pragma once
13#include "TnbDef.h"
14
15
16
17//TNB Library
18namespace TNB
19{
20
21
22
33{
34public:
35
40 CDcSelectAssistant(HDC dc) : m_dc(dc)
41 , m_textColor(CLR_INVALID), m_backColor(CLR_INVALID), m_backMode(-1)
42 , m_font(NULL), m_brush(NULL), m_pen(NULL), m_bitmap(NULL)
43 {
44 }
45
51 {
52 Restore();
53 }
54
59 void Restore(void)
60 {
61 if ( m_textColor != CLR_INVALID )
62 {
63 ::SetTextColor(m_dc, m_textColor);
64 m_textColor = CLR_INVALID;
65 }
66 if ( m_backColor != CLR_INVALID )
67 {
68 ::SetBkColor(m_dc,m_backColor);
69 m_backColor = CLR_INVALID;
70 }
71 if ( m_backMode >= 0 )
72 {
73 ::SetBkMode(m_dc, m_backMode);
74 m_backMode = -1;
75 }
76 if ( m_font != NULL )
77 {
78 ::SelectObject(m_dc, m_font);
79 m_font = NULL;
80 }
81 if ( m_brush != NULL )
82 {
83 ::SelectObject(m_dc, m_brush);
84 m_brush = NULL;
85 }
86 if ( m_pen != NULL )
87 {
88 ::SelectObject(m_dc, m_pen);
89 m_pen = NULL;
90 }
91 if ( m_bitmap != NULL )
92 {
93 ::SelectObject(m_dc, m_bitmap);
94 m_bitmap = NULL;
95 }
96 }
97
102 void SetTextColor(COLORREF c)
103 {
104 COLORREF r = ::SetTextColor(m_dc, c);
105 if ( m_textColor == CLR_INVALID )
106 {
107 m_textColor = r;
108 }
109 }
110
115 void SetBkColor(COLORREF c)
116 {
117 COLORREF r = ::SetBkColor(m_dc, c);
118 if ( m_backColor == CLR_INVALID )
119 {
120 m_backColor = r;
121 }
122 }
123
128 void SetBkMode(int mode)
129 {
130 int r = ::SetBkMode(m_dc, mode);
131 if ( m_backMode < 0 )
132 {
133 m_backMode = r;
134 }
135 }
136
141 void SelectBrush(HBRUSH brush)
142 {
143 HGDIOBJ r = ::SelectObject(m_dc, brush);
144 if ( m_brush == NULL )
145 {
146 m_brush = static_cast<HBRUSH>(r);
147 }
148 }
149
154 void SelectPen(HPEN pen)
155 {
156 HGDIOBJ r = ::SelectObject(m_dc, pen);
157 if ( m_pen == NULL )
158 {
159 m_pen = static_cast<HPEN>(r);
160 }
161 }
162
167 void SelectBitmap(HBITMAP bitmap)
168 {
169 HGDIOBJ r = ::SelectObject(m_dc, bitmap);
170 if ( m_bitmap == NULL )
171 {
172 m_bitmap = static_cast<HBITMAP>(r);
173 }
174 }
175
180 void SelectFont(HFONT font)
181 {
182 HGDIOBJ r = ::SelectObject(m_dc, font);
183 if ( m_font == NULL )
184 {
185 m_font = static_cast<HFONT>(r);
186 }
187 }
188
189 #ifdef __AFX_H__
190
195 void SelectFont(CFont* pFont)
196 {
197 if ( pFont != NULL )
198 {
199 SelectFont(static_cast<HFONT>(pFont->GetSafeHandle()));
200 }
201 }
202
203 #endif
204
205private:
206 HDC m_dc;
207 COLORREF m_textColor;
208 COLORREF m_backColor;
209 int m_backMode;
210 HFONT m_font;
211 HBRUSH m_brush;
212 HPEN m_pen;
213 HBITMAP m_bitmap;
214};
215
216
217
218};//TNB
TNBライブラリの定義ヘッダ
[ETC] コピー不可能スーパークラス.
Definition: TnbDef.h:599
デバイステキストセレクトアシスタント
void SelectFont(CFont *pFont)
[選択] フォント選択.
void SelectBrush(HBRUSH brush)
[選択] ブラシ選択.
void SetTextColor(COLORREF c)
[設定] 文字色設定.
void SelectBitmap(HBITMAP bitmap)
[選択] 画像選択.
void Restore(void)
[設定] リストア.
void SetBkColor(COLORREF c)
[設定] 背景色設定.
void SetBkMode(int mode)
[設定] 背景モード設定.
void SelectPen(HPEN pen)
[選択] ペン選択.
CDcSelectAssistant(HDC dc)
コンストラクタ.
~CDcSelectAssistant(void)
デストラクタ.
void SelectFont(HFONT font)
[選択] フォント選択.
TNB Library
Definition: TnbDoxyTitle.txt:2