CListCtrl 交替行繪製不同背景色(轉)
阿新 • • 發佈:2019-01-30
此響應WM_ERASEBKGND訊息
BOOL MyList::OnEraseBkgnd(CDC*pDC)
{
// TODO:在此新增訊息處理程式程式碼和/或呼叫預設值
CRect rect;
GetClientRect(rect);
POINTmypoint;
CBrush brush0(m_colRow1);
CBrush brush1(m_colRow2);
int chunk_height=GetCountPerPage();
pDC->FillRect(&rect,&brush1); for (inti=0;i<=chunk_height;i++)
{
GetItemPosition(i,&mypoint);
rect.top=mypoint.y ;
GetItemPosition(i+1,&mypoint);
rect.bottom =mypoint.y;
pDC->FillRect(&rect,i %2 ? &brush1 :&brush0);
} brush0.DeleteObject();
brush1.DeleteObject(); return FALSE;
} 此響應訊息NM_CUSTOMDRAW void MyList::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT*pResult)
{ *pResult =0;
LPNMLVCUSTOMDRAW lplvcd =(LPNMLVCUSTOMDRAW)pNMHDR;
int iRow = lplvcd->nmcd.dwItemSpec; switch(lplvcd->nmcd.dwDrawStage)
{
caseCDDS_PREPAINT :
{
*pResult = CDRF_NOTIFYITEMDRAW;
return;
} //Modify item text and or background
caseCDDS_ITEMPREPAINT:
{
lplvcd->clrText = RGB(0,0,0);
// 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
caseCDDS_SUBITEM | CDDS_PREPAINT | CDDS_ITEM:
{
if(iRow %2){
lplvcd->clrTextBk = m_colRow2;
}
else{
lplvcd->clrTextBk = m_colRow1;
}
*pResult = CDRF_DODEFAULT;
return;
}
}
}
轉自:http://blog.sina.com.cn/s/blog_4ad18f56010006s8.html
{
// TODO:在此新增訊息處理程式程式碼和/或呼叫預設值
CRect rect;
GetClientRect(rect);
POINTmypoint;
CBrush brush0(m_colRow1);
CBrush brush1(m_colRow2);
int chunk_height=GetCountPerPage();
pDC->FillRect(&rect,&brush1); for (inti=0;i<=chunk_height;i++)
{
GetItemPosition(i,&mypoint);
rect.top=mypoint.y ;
GetItemPosition(i+1,&mypoint);
rect.bottom =mypoint.y;
pDC->FillRect(&rect,i %2 ? &brush1 :&brush0);
} brush0.DeleteObject();
brush1.DeleteObject(); return FALSE;
} 此響應訊息NM_CUSTOMDRAW void MyList::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT*pResult)
{ *pResult =0;
LPNMLVCUSTOMDRAW lplvcd =(LPNMLVCUSTOMDRAW)pNMHDR;
int iRow = lplvcd->nmcd.dwItemSpec; switch(lplvcd->nmcd.dwDrawStage)
{
caseCDDS_PREPAINT :
{
*pResult = CDRF_NOTIFYITEMDRAW;
return;
} //Modify item text and or background
caseCDDS_ITEMPREPAINT:
{
lplvcd->clrText = RGB(0,0,0);
// 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
caseCDDS_SUBITEM | CDDS_PREPAINT | CDDS_ITEM:
{
if(iRow %2){
lplvcd->clrTextBk = m_colRow2;
}
else{
lplvcd->clrTextBk = m_colRow1;
}
*pResult = CDRF_DODEFAULT;
return;
}
}
}
轉自:http://blog.sina.com.cn/s/blog_4ad18f56010006s8.html