扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
template <class T> class COwnerDraw { public: BEGIN_MSG_MAP(COwnerDraw<T>) MESSAGE_HANDLER(WM_DRAWITEM, OnDrawItem) MESSAGE_HANDLER(WM_MEASUREITEM, OnMeasureItem) MESSAGE_HANDLER(WM_COMPAREITEM, OnCompareItem) MESSAGE_HANDLER(WM_DELETEITEM, OnDeleteItem) ALT_MSG_MAP(1) MESSAGE_HANDLER(OCM_DRAWITEM, OnDrawItem) MESSAGE_HANDLER(OCM_MEASUREITEM, OnMeasureItem) MESSAGE_HANDLER(OCM_COMPAREITEM, OnCompareItem) MESSAGE_HANDLER(OCM_DELETEITEM, OnDeleteItem) END_MSG_MAP() }; |
class CSomeDlg : public COwnerDraw<CSomeDlg>, ... { BEGIN_MSG_MAP(CSomeDlg) //... CHAIN_MSG_MAP(COwnerDraw<CSomeDlg>) END_MSG_MAP() void DrawItem ( LPDRAWITEMSTRUCT lpdis ); }; |
class CSomeButtonImpl : public COwnerDraw<CSomeButtonImpl>, ... { BEGIN_MSG_MAP(CSomeButtonImpl) //... CHAIN_MSG_MAP_ALT(COwnerDraw<CSomeButtonImpl>, 1) DEFAULT_REFLECTION_HANDLER() END_MSG_MAP() void DrawItem ( LPDRAWITEMSTRUCT lpdis ); }; |
void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct); void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct); int CompareItem(LPCOMPAREITEMSTRUCT lpCompareItemStruct); void DeleteItem(LPDELETEITEMSTRUCT lpDeleteItemStruct); |
class CODButtonImpl : public CWindowImpl<CODButtonImpl, CButton>, public COwnerDraw<CODButtonImpl> { public: BEGIN_MSG_MAP_EX(CODButtonImpl) CHAIN_MSG_MAP_ALT(COwnerDraw<CODButtonImpl>, 1) DEFAULT_REFLECTION_HANDLER() END_MSG_MAP() void DrawItem ( LPDRAWITEMSTRUCT lpdis ); }; |
void CODButtonImpl::DrawItem ( LPDRAWITEMSTRUCT lpdis ) { // NOTE: m_bmp is a CBitmap init''ed in the constructor. CDCHandle dc = lpdis->hDC; CDC dcMem; dcMem.CreateCompatibleDC ( dc ); dc.SaveDC(); dcMem.SaveDC(); // Draw the button''s background, red if it has the focus, blue if not. if ( lpdis->itemState & ODS_FOCUS ) dc.FillSolidRect ( &lpdis->rcItem, RGB(255,0,0) ); else dc.FillSolidRect ( &lpdis->rcItem, RGB(0,0,255) ); // Draw the bitmap in the top-left, or offset by 1 pixel if the button // is clicked. dcMem.SelectBitmap ( m_bmp ); if ( lpdis->itemState & ODS_SELECTED ) dc.BitBlt ( 1, 1, 80, 80, dcMem, 0, 0, SRCCOPY ); else dc.BitBlt ( 0, 0, 80, 80, dcMem, 0, 0, SRCCOPY ); dcMem.RestoreDC(-1); dc.RestoreDC(-1); } |
DWORD OnPrePaint(int idCtrl, LPNMCUSTOMDRAW lpNMCD); DWORD OnPostPaint(int idCtrl, LPNMCUSTOMDRAW lpNMCD); DWORD OnPreErase(int idCtrl, LPNMCUSTOMDRAW lpNMCD); DWORD OnPostErase(int idCtrl, LPNMCUSTOMDRAW lpNMCD); DWORD OnItemPrePaint(int idCtrl, LPNMCUSTOMDRAW lpNMCD); DWORD OnItemPostPaint(int idCtrl, LPNMCUSTOMDRAW lpNMCD); DWORD OnItemPreErase(int idCtrl, LPNMCUSTOMDRAW lpNMCD); DWORD OnItemPostEraset(int idCtrl, LPNMCUSTOMDRAW lpNMCD); DWORD OnSubItemPrePaint(int idCtrl, LPNMCUSTOMDRAW lpNMCD); |
DWORD CBuffyTreeCtrl::OnPrePaint(int idCtrl, LPNMCUSTOMDRAW lpNMCD) { return CDRF_NOTIFYITEMDRAW; } DWORD CBuffyTreeCtrl::OnItemPrePaint(int idCtrl, LPNMCUSTOMDRAW lpNMCD) { if ( 1 == lpNMCD->lItemlParam ) pnmtv->clrText = RGB(0,128,0); return CDRF_DODEFAULT; } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者