第一步,添加NM_CUSTOMDRAW消息,将ON_NOTIFY_REFLECT(NM_CUSTOMDRAW, OnCustomDraw)消息添加到你的.cpp文件中,将afx_msg void OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult);添加到你的.h中,然后在项目中添加如下代码就可以了。
你自己看吧
void CColourListView::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
*pResult = 0; COLORREF dwColourTxt = 0;
COLORREF dwColourBk = RGB(255, 255, 255); LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)pNMHDR; switch(lplvcd->nmcd.dwDrawStage)
{
case CDDS_PREPAINT :
{
*pResult = CDRF_NOTIFYITEMDRAW;
return;
}
// Modify item text and or background
//改变项目的文本和背景
case CDDS_ITEMPREPAINT:
{
if(lplvcd->nmcd.dwItemSpec == 0)
{
dwColourTxt = RGB(255, 0, 0); // Red
}
else if(lplvcd->nmcd.dwItemSpec == 1)
{
dwColourTxt = RGB(0, 255, 0); // Green
}
else
{
dwColourTxt = RGB(0, 0, 255); // Blue
}
lplvcd->clrText = dwColourTxt;
// If you want the sub items the same as the item set *pResult
// to CDRF_NEWFONT
*pResult = CDRF_NOTIFYSUBITEMDRAW;
return;
} // Modify sub item text and or background
case CDDS_SUBITEM | CDDS_PREPAINT | CDDS_ITEM:
{
// Ignore the first sub item it is the item handled above
if(lplvcd->iSubItem != 0)
{
// First sub item
if(lplvcd->iSubItem == 1)
{
dwColourTxt = RGB(0, 127, 127); // Pale blue
dwColourBk = RGB(255, 255, 255); // White
}
// All sub items after the first
else
{
dwColourTxt = RGB(255, 255, 255); // White
if(lplvcd->nmcd.dwItemSpec == 0)
{
dwColourBk = RGB(255, 0, 0); // Red
}
else if(lplvcd->nmcd.dwItemSpec == 1)
{
dwColourBk = RGB(0, 255, 0); // Green
}
else
{
dwColourBk = RGB(0, 0, 255); // Blue
}
}
lplvcd->clrText = dwColourTxt;
lplvcd->clrTextBk = dwColourBk;
}
*pResult = CDRF_NEWFONT;
return;
}
}
}
你自己看吧
void CColourListView::OnCustomDraw(NMHDR* pNMHDR, LRESULT* pResult)
{
*pResult = 0; COLORREF dwColourTxt = 0;
COLORREF dwColourBk = RGB(255, 255, 255); LPNMLVCUSTOMDRAW lplvcd = (LPNMLVCUSTOMDRAW)pNMHDR; switch(lplvcd->nmcd.dwDrawStage)
{
case CDDS_PREPAINT :
{
*pResult = CDRF_NOTIFYITEMDRAW;
return;
}
// Modify item text and or background
//改变项目的文本和背景
case CDDS_ITEMPREPAINT:
{
if(lplvcd->nmcd.dwItemSpec == 0)
{
dwColourTxt = RGB(255, 0, 0); // Red
}
else if(lplvcd->nmcd.dwItemSpec == 1)
{
dwColourTxt = RGB(0, 255, 0); // Green
}
else
{
dwColourTxt = RGB(0, 0, 255); // Blue
}
lplvcd->clrText = dwColourTxt;
// If you want the sub items the same as the item set *pResult
// to CDRF_NEWFONT
*pResult = CDRF_NOTIFYSUBITEMDRAW;
return;
} // Modify sub item text and or background
case CDDS_SUBITEM | CDDS_PREPAINT | CDDS_ITEM:
{
// Ignore the first sub item it is the item handled above
if(lplvcd->iSubItem != 0)
{
// First sub item
if(lplvcd->iSubItem == 1)
{
dwColourTxt = RGB(0, 127, 127); // Pale blue
dwColourBk = RGB(255, 255, 255); // White
}
// All sub items after the first
else
{
dwColourTxt = RGB(255, 255, 255); // White
if(lplvcd->nmcd.dwItemSpec == 0)
{
dwColourBk = RGB(255, 0, 0); // Red
}
else if(lplvcd->nmcd.dwItemSpec == 1)
{
dwColourBk = RGB(0, 255, 0); // Green
}
else
{
dwColourBk = RGB(0, 0, 255); // Blue
}
}
lplvcd->clrText = dwColourTxt;
lplvcd->clrTextBk = dwColourBk;
}
*pResult = CDRF_NEWFONT;
return;
}
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货