TNB Library
TnbMfcTabCtrlEx.h
[詳解]
1#pragma once
11#include "TnbMfcCommon.h"
12#include "TnbTextDrawer.h"
13
14
15
16//TNB Library
17namespace TNB {
18namespace MFC {
19
20
21
37class CTabCtrlEx : public CTabCtrl
38{
39 DEFSUPER(CTabCtrl);
40public:
41
43 CTabCtrlEx(void) : m_selectTextColor(CLR_INVALID), m_selectBackColor(CLR_INVALID), m_isAttachedSpin(false)
44 {
45 }
46
52 void SetSelectedColor(COLORREF text, COLORREF back = CLR_INVALID)
53 {
54 m_selectTextColor = text;
55 m_selectBackColor = back;
56 }
57
63 CString GetItemText(int nItem) const
64 {
65 TC_ITEM tci;
66 CString s;
67 tci.mask = TCIF_TEXT;
68 tci.pszText = s.GetBuffer(512);
69 tci.cchTextMax = 511;
70 if ( _super::GetItem(nItem, &tci) )
71 {
72 s.ReleaseBuffer();
73 }
74 else
75 {
76 s.ReleaseBuffer();
77 s.Empty();
78 }
79 return s;
80 }
81
89 bool SetItemText(int nItem, LPCTSTR lpszText)
90 {
91 TC_ITEM tci;
92 CString s = lpszText;
93 tci.mask = TCIF_TEXT;
94 tci.pszText = s.GetBuffer(512);
95 tci.cchTextMax = 511;
96 BOOL r = _super::SetItem(nItem, &tci);
97 s.ReleaseBuffer();
98 return !! r;
99 }
100
106 CSpinButtonCtrl* GetSpinButtonCtrl(void)
107 {
108 if ( ! m_isAttachedSpin && ! ::IsWindow(m_spin) )
109 {
110 m_spin.SubclassWindow(GetDlgItem(1)->GetSafeHwnd());
111 }
112 return &m_spin;
113 }
114
115protected:
116
122 virtual void PreSubclassWindow(void)
123 {
124 m_isAttachedSpin = false;
125 _super::ModifyStyle(0, TCS_OWNERDRAWFIXED);
126 _super::PreSubclassWindow();
127 }
128
138 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
139 {
140 if ( message == WM_CREATE )
141 {
142 m_isAttachedSpin = false;
143 }
144 if ( message == WM_DESTROY )
145 {
146 if ( ::IsWindow(m_spin) )
147 {
148 m_spin.UnsubclassWindow();
149 }
150 }
151 if ( ! m_isAttachedSpin && ! ::IsWindow(m_spin) )
152 {
153 HWND h = GetDlgItem(1)->GetSafeHwnd();
154 if ( h != NULL )
155 {
156 m_spin.SubclassWindow(h);
157 m_isAttachedSpin = true;
158 }
159 }
160 if ( message == WM_ERASEBKGND )
161 {
162 HDC dc = reinterpret_cast<HDC>(wParam);
163 LRESULT res = _super::GetParent()->SendMessage(WM_CTLCOLORBTN, reinterpret_cast<WPARAM>(dc), _super::GetDlgCtrlID());
164 HBRUSH b = reinterpret_cast<HBRUSH>(res);
165 if ( b != NULL )
166 {
167 CRect rc;
168 GetClientRect(rc);
169 POINT po;
170 MFCLIB::GetControlPos(this, po);
171 ::SetBrushOrgEx(dc, po.x, po.y, NULL);
172 ::FillRect(dc, &rc, b);
173 return FALSE;
174 }
175 }
176 return _super::WindowProc(message, wParam, lParam);
177 }
178
184 void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
185 {
186 if ( lpDrawItemStruct->CtlType != ODT_TAB || lpDrawItemStruct->hwndItem != _super::GetSafeHwnd() )
187 {
188 return;
189 }
190 const CString& s = GetItemText(lpDrawItemStruct->itemID);
191 RECT rc = lpDrawItemStruct->rcItem;
192 HDC dc = lpDrawItemStruct->hDC;
193 LRESULT res = _super::GetParent()->SendMessage(WM_CTLCOLORBTN, reinterpret_cast<WPARAM>(dc), _super::GetDlgCtrlID());
194 HBRUSH b = reinterpret_cast<HBRUSH>(res);
195 COLORREF c = ::GetTextColor(dc);
196 if ( (lpDrawItemStruct->itemState & ODS_SELECTED) != 0 )
197 {
198 if ( IS_RGBVALUE(m_selectBackColor) )
199 {
200 CBrush br;
201 br.CreateSolidBrush(m_selectBackColor);
202 ::FillRect(dc, &rc, br);
203 }
204 else
205 {
206 ::FillRect(dc, &rc, b);
207 }
208 if ( IS_RGBVALUE(m_selectTextColor) )
209 {
210 c = m_selectTextColor;
211 }
212 }
213 else
214 {
215 ::FillRect(dc, &rc, b);
216 }
217 ::SetBkMode(dc, TRANSPARENT);
218 rc.top += 5;
219// rc.bottom -= 3;//下付きの場合
220
221 if ( false )
222 {
223 LOGFONT lf;
224 CFont* pFont = GetFont();
225 pFont->GetLogFont(&lf);
226 lf.lfEscapement = 900;
227 CStr s = "@";
228 s += lf.lfFaceName;
229 _tcscpy(lf.lfFaceName, s);
230 CFont f;
231 f.CreateFontIndirect(&lf);
232 HGDIOBJ h = ::SelectObject(dc, f);
233 CTextDrawer::DrawTextRect(dc, rc, DT_CENTER, c, s);
234 ::SelectObject(dc, h);
235 return;
236 }
237
238
239 CTextDrawer::DrawTextRect(dc, rc, DT_CENTER, c, s);
240 }
241
242private:
243 COLORREF m_selectTextColor;
244 COLORREF m_selectBackColor;
245 CSpinButtonCtrl m_spin;
246 bool m_isAttachedSpin;
247};
248
249
250
251}; // MFC
252}; // TNB
MFCコントロール共通のヘッダ
テキスト描画関係のヘッダ
タブコントロール.
HWND GetSafeHwnd(void) const
[取得] ウィンドウハンドル取得.
static bool DrawTextRect(RECT &_rect, HDC dc, DWORD drawStyle, const POINT &offset, COLORREF color1, COLORREF color2, LPCTSTR str)
[表示] 範囲文字表示.
タブコントロール
void SetSelectedColor(COLORREF text, COLORREF back=CLR_INVALID)
[設定] 選択タブカラー設定.
CTabCtrlEx(void)
コンストラクタ
bool SetItemText(int nItem, LPCTSTR lpszText)
[設定] Item文字列設定.
CSpinButtonCtrl * GetSpinButtonCtrl(void)
[取得] スピンボタン取得.
CString GetItemText(int nItem) const
[取得] Item文字列取得.
virtual void PreSubclassWindow(void)
[通知] subclassing/unsubclassing functions.
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
[通知] for processing Windows messages.
void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
[通知] オーナードロー処理.
bool GetControlPos(CWnd *pWnd, POINT &_po)
[取得] コントロール位置取得.
Definition: TnbMfcCommon.h:80
TNB Library
Definition: TnbDoxyTitle.txt:2