TNB Library
TnbMfcAbstractCustomDraw.h
[詳解]
1#pragma once
11#include "TnbMfcCommon.h"
12
13
14
15//TNB Library
16namespace TNB {
17namespace MFC {
18
19
20
30{
31protected:
32
35 {
36 HDC dc;
37 CRect rect;
38 DWORD_PTR itemNo;
39 DWORD subItemNo;
40 UINT state;
63 COLORREF textColor;
64 COLORREF backColor;
65 };
66
76 virtual void OnBeginItemPaint(HDC dc) = 0;
77
84 virtual void OnEndItemPaint(HDC dc) = 0;
85
94 virtual LRESULT OnItemPainting(TDrawParam* pParam) = 0;
95
101 virtual void OnItemPainted(const TDrawParam* pParam) = 0;
102
108 virtual bool HasSubItem(void) const = 0;
109
117 virtual void OnCalcItemRect(TDrawParam& _pa, bool isSub) = 0;
118
129 BOOL OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT* _pResult)
130 {
131 if ( message == WM_NOTIFY )
132 {
133 LPNMHDR lpNmHdr = reinterpret_cast<LPNMHDR>(lParam);
134 if ( lpNmHdr->code == NM_CUSTOMDRAW )
135 {
136 LPNMLVCUSTOMDRAW lpLvCd = reinterpret_cast<LPNMLVCUSTOMDRAW>(lParam);
137 *_pResult = m_OnCustomDraw(lpLvCd);
138 return TRUE;
139 }
140 }
141 return FALSE;
142 }
143
144private:
145
147 LRESULT m_OnItemPaintSub(LPNMLVCUSTOMDRAW P, int subItemNo)
148 {
149 TDrawParam pa;
150 pa.dc = P->nmcd.hdc;
151 pa.itemNo = P->nmcd.dwItemSpec;
152 pa.subItemNo = subItemNo;
153 pa.state = P->nmcd.uItemState;
154 pa.textColor = P->clrText;
155 pa.backColor = P->clrTextBk;
156 pa.rect = P->nmcd.rc;
157 OnCalcItemRect(pa, true);
158 LRESULT r = OnItemPainting(&pa);
159 P->clrText = pa.textColor;
160 P->clrTextBk = pa.backColor;
161 return r;
162 }
163
165 LRESULT m_OnCustomDraw(LPNMLVCUSTOMDRAW P)
166 {
167 switch ( P->nmcd.dwDrawStage )
168 {
169 case CDDS_PREPAINT:
170 OnBeginItemPaint(P->nmcd.hdc);
171 return CDRF_NOTIFYITEMDRAW | CDRF_NOTIFYPOSTPAINT;
172 case CDDS_POSTPAINT:
173 OnEndItemPaint(P->nmcd.hdc) ;
174 return CDRF_DODEFAULT;
175 case CDDS_ITEMPOSTPAINT:
176 {
177 TDrawParam pa;
178 pa.dc = P->nmcd.hdc;
179 pa.itemNo = P->nmcd.dwItemSpec;
180 pa.subItemNo = 0;
181 pa.state = P->nmcd.uItemState;
182 pa.textColor = P->clrText;
183 pa.backColor = P->clrTextBk;
184 pa.rect = P->nmcd.rc;
185 OnCalcItemRect(pa, false);
186 OnItemPainted(&pa);
187 }
188 break;
189 case CDDS_ITEMPREPAINT:
190 if ( ! HasSubItem() )
191 {
192 return m_OnItemPaintSub(P, 0) | CDRF_NOTIFYPOSTPAINT;
193 }
194 return CDRF_NOTIFYSUBITEMDRAW | CDRF_NOTIFYPOSTPAINT;
195 case CDDS_ITEMPREPAINT | CDDS_SUBITEM:
196 return m_OnItemPaintSub(P, P->iSubItem);
197 }
198 return CDRF_DODEFAULT;
199 }
200
201public:
202
205 {
206 }
207};
208
209
210
211}; // MFC
212}; // TNB
MFCコントロール共通のヘッダ
カスタム描画抽象コントロール
virtual void OnItemPainted(const TDrawParam *pParam)=0
[通知] アイテム描画終わり.
virtual bool HasSubItem(void) const =0
[確認] サブアイテム概念の有無
virtual void OnEndItemPaint(HDC dc)=0
[通知] 描画終了.
virtual void OnCalcItemRect(TDrawParam &_pa, bool isSub)=0
[確認] アイテムRECT計算
BOOL OnChildNotify(UINT message, WPARAM wParam, LPARAM lParam, LRESULT *_pResult)
[通知] for notifications from parent
CAbstractCustomDraw(void)
コンストラクタ
virtual LRESULT OnItemPainting(TDrawParam *pParam)=0
[通知] アイテム描画.
virtual void OnBeginItemPaint(HDC dc)=0
[通知] 描画開始.
TNB Library
Definition: TnbDoxyTitle.txt:2
DWORD subItemNo
サブアイテムナンバー
DWORD_PTR itemNo
アイテムナンバー