if (pLVCD == NULL)
return;
// the step expain to see see ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.2052/shellcc/platform/commctls/custdraw/custdraw.htm#CustomDraw_Prepaint
// first step, we want custom draw
if (pLVCD->nmcd.dwDrawStage == CDDS_PREPAINT)
{
*pResult = CDRF_NOTIFYITEMDRAW;
return;
}
// second setp, we want draw each sub item
if (pLVCD->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
{
*pResult = CDRF_NOTIFYSUBITEMDRAW;
return;
}
// third step, we do our custom draw
if (pLVCD->nmcd.dwDrawStage & (CDDS_SUBITEM | CDDS_PREPAINT))
{
DoCustomDraw(pLVCD);
*pResult = CDRF_NEWFONT;
}
}
当ListView向程序员提问是否需要进行CUSTOMDRAW时,返回需要的回答,直到第三步。pLVCD->nmcd.dwDrawStage表示ListView的询问,而*pResult则包含程序员的回答。另外,在第三步,(pLVCD->nmcd.dwDrawStage & (CDDS_SUBITEM | CDDS_PREPAINT)时,按照MSDN的描述应该是==,但实际上应该是 &。
DoCustomDraw 是我们自己的函数,它具体的控制如何绘制,在例子中,它用交替的背景进行绘制,并且每隔3列绘制成红色,将选中的列背景绘制为淡蓝色
void CSampleListCtrl::DoCustomDraw(LPNMLVCUSTOMDRAW pLVCD)
{