case CDDS_ITEMPOSTPAINT:
{
// Item PostPaint
// restore old font if any
if (m_pOldItemFont) {
if (! pDC) pDC = CDC::FromHandle(hdc);
pDC->SelectObject(m_pOldItemFont);
m_pOldItemFont = NULL;
}
// do we want to do any extra drawing?
if (IsItemPostDraw()) {
if (! pDC) pDC = CDC::FromHandle(hdc);
OnItemPostDraw(pDC,nItem,nState,lParam);
}
}
break;
case CDDS_POSTPAINT:
{
// Item PostPaint
// do we want to do any extra drawing?
if (IsPostDraw()) {
if (! pDC) pDC = CDC::FromHandle(hdc);
CRect r(pNMLVCUSTOMDRAW->nmcd.rc);
OnPostDraw(pDC,r);
}
}
break;
}
ASSERT(CDRF_DODEFAULT==0);
*pResult = 0;
if (bNotifyPostPaint) {
*pResult |= CDRF_NOTIFYPOSTPAINT;
}
if (bNotifyItemDraw) {
*pResult |= CDRF_NOTIFYITEMDRAW;
}
if (bNotifySubItemDraw) {
*pResult |= CDRF_NOTIFYSUBITEMDRAW;
}
if (bNewFont) {
*pResult |= CDRF_NEWFONT;
}
if (bSkipDefault) {
*pResult |= CDRF_SKIPDEFAULT;
}
if (*pResult == 0) {
// redundant as CDRF_DODEFAULT==0 anyway
// but shouldn't depend on this in our code
*pResult = CDRF_DODEFAULT;
}
}
Phew! That's a fair bit of code. The good news? There's less code left for us to write when we derive from CListCtrlWithCustomDraw.
To make this work, those virtual functions need to be defined. The defaults for these functions are to do nothing; so using the CListCtrlWithCustomDraw on its own will work the same as a standard list control. It is only when you derive from this class and override some of the virtual functions that the ListView control changes appearance. If you do not override them, then you get the standard behaviour.
To start with, here are the additions to the class declaration for CListCtrlWithCustomDraw:
评论