在listctrl的NM_Customdraw消息响应函数里弄:例子如下
LRESULT CXXXDialog::OnNMCustomdrawListLayer(int idCtrl, LPNMHDR pNMHDR, BOOL& bHandled)
{
NMLVCUSTOMDRAW* pLVCD = reinterpret_cast
pLVCD->clrFace=RGB(255,0,0);
if ( CDDS_PREPAINT ==pLVCD->nmcd.dwDrawStage )
{
return CDRF_NOTIFYITEMDRAW;
}
else if ( CDDS_ITEMPREPAINT == pLVCD->nmcd.dwDrawStage )
{//这里可以编写代码设置某一行的颜色
int nItem=static_cast
if (nItem==1)
{
long r=100;
long g=0;
long b=0;
pLVCD->clrTextBk=RGB(r,g,b);
}
return CDRF_NOTIFYSUBITEMDRAW;
}
else if ( (CDDS_ITEMPREPAINT | CDDS_SUBITEM) == pLVCD->nmcd.dwDrawStage )
{//这里可以设定具体某一行某一格的背景颜色
int nItem=static_cast
int nSubItem=pLVCD->iSubItem;
if (nSubItem==4)
{
long r=100;
long g=0;
long b=0;
pLVCD->clrTextBk=RGB(r,g,b);
}
}
return 0;
}