[英]Change Background color of full column of CListCtrl in MFC
Ive made a CListCtrl in Report View in MFC. 我已经在MFC的报表视图中创建了CListCtrl。 I want to color the first column (the full column, not only those cells where an Item is) with a grey background.
我想用灰色背景为第一列(整列,不仅是项目所在的单元格)着色。
How can I do this? 我怎样才能做到这一点? Thank
谢谢
The way you will implement this is color each cell of the first row individually. 实现此方法的方法是分别为第一行的每个单元格上色。 The code will look something like below, which basically a blue print but It should work (Note:I haven't test this for this post).
该代码将如下所示,基本上是一个蓝图,但它应该可以工作(注意:本文尚未对此进行测试)。 You will have to use
lplvcd->iSubItem
and paint the first column of each row. 您将必须使用
lplvcd->iSubItem
并绘制每行的第一列。
void MyList::OnNMCustomdraw(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVCUSTOMDRAW* cd = reinterpret_cast<NMLVCUSTOMDRAW*>(pNMHDR);
*pResult = CDRF_DODEFAULT;
switch( cd->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
*pResult = CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
{
int rowNumber = cd->nmcd.dwItemSpec;
bool highlightRow = (bool)GetItemData(rowNumber);
if (highlightRow)
{
COLORREF backgroundColor;
backgroundColor = RGB(255, 0, 0);
cd->clrTextBk = backgroundColor;
}
}
break;
case CDDS_SUBITEM | CDDS_ITEMPREPAINT:
{
// something like if(lplvcd->iSubItem == 0 ) to paint first column
lplvcd->clrText = RGB(0,0,255);
*pResult = CDRF_NEWFONT;
return;
}
default:
break;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.