如何设置CListCtrl中任一行的背景颜色,
困扰我很久的一个问题,总得不到预想的效果.
比如说设置CListCtrl中第一行的为蓝色,
第二行为红色,这样交替变色。
多谢高手指点一二,感激涕零
问题点数:20、回复次数:4Top
1 楼jinghao666666(努力工作!!!)回复于 2006-12-03 21:01:09 得分 0
查下msdn,或从网上下个别人写好的。Top
2 楼zhshgap(努力学习)回复于 2006-12-03 21:04:41 得分 0
这个只能自定义派生clistctrl类
网上应该有很多例子Top
3 楼erdgzw(编译通过那一刻感觉真好)回复于 2006-12-03 22:11:11 得分 0
你应该使用WindowsApi来创建List Control,并启用拥有者自绘。Top
4 楼ljhjason(小鬼)回复于 2006-12-03 22:15:20 得分 0
我这个是改某列的字体,修改一下就可以改颜色.
void CMyDlg::OnNMCustomdrawList1(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLVCUSTOMDRAW pLVCD = reinterpret_cast<LPNMLVCUSTOMDRAW>(pNMHDR);
// Take the default processing unless we set this to something else below.
*pResult = CDRF_DODEFAULT;
// First thing - check the draw stage. If it's the control's prepaint
// stage, then tell Windows we want messages for every item.
if (pLVCD->nmcd.dwDrawStage == CDDS_PREPAINT)
{
*pResult = CDRF_NOTIFYITEMDRAW;
}
else if (pLVCD->nmcd.dwDrawStage == CDDS_ITEMPREPAINT)
{
// This is the notification message for an item. We'll request
// notifications before each subitem's prepaint stage.
*pResult = CDRF_NOTIFYSUBITEMDRAW;//CDRF_NOTIFYPOSTPAINT;
}
else if (pLVCD->nmcd.dwDrawStage == (CDDS_ITEMPREPAINT | CDDS_SUBITEM))
{
// This is the prepaint stage for a subitem. Here's where we set the
// item's text and background colors. Our return value will tell
// Windows to draw the subitem itself, but it will use the new colors
// we set here.
//int nItem = static_cast<int> (pLVCD->nmcd.dwItemSpec);
int nSubItem = pLVCD->iSubItem;
CDC* pDC = CDC::FromHandle(pLVCD->nmcd.hdc);
if(nSubItem==3)
{
pDC->SelectObject(&font);
}else
{
pDC->SelectObject(oldfont);
}
*pResult = CDRF_DODEFAULT;
}
}Top




