The following code example shows how application-defined function processes custom draw notification messages sent by a child list view control. Upon receiving the prepaint notification CDDS_PREPAINT, the function requests item-specific notifications by returning CDRF_NOTIFYITEMDRAW. When it receives the subsequent item-specific notifications, it selects a previously created font into the provided device context and specifies new colors before returning CDRF_NEWFONT.
LRESULT DoNotify(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
LPNMLISTVIEW pnm = (LPNMLISTVIEW)lParam;
switch (pnm->hdr.code){
case NM_CUSTOMDRAW:{
LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)lParam;
if(lplvcd->nmcd.dwDrawStage == CDDS_PREPAINT)
return CDRF_NOTIFYITEMDRAW;
if(lplvcd->nmcd.dwDrawStage == CDDS_ITEMPREPAINT){
if(!(lplvcd->nmcd.dwItemSpec % 3))
SelectObject(lplvcd->nmcd.hdc, g_hNewFont);
else
return(CDRF_DODEFAULT);
lplvcd->clrText = RGB(150, 75, 150);
lplvcd->clrTextBk = RGB(255,255,255);
return CDRF_NEWFONT;
}
}
default:
break;
}
return 0;
}