CListCtrl各行背景不同出现的问题

coldplay968 coldplay968 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
该代码来源于www.codeproject.com

m_colRow1 = RGB(240,247,249);
m_colRow2 = RGB(229,232,239);

BOOL MyClistCtrl::OnEraseBkgnd(CDC* pDC)
{ CRect rect;
MyClistCtrl::GetClientRect(rect);

POINT mypoint;

CBrush brush0(m_colRow1);
CBrush brush1(m_colRow2);

int chunk_height=GetCountPerPage();
// pDC->FillRect(&rect,&brush1);

for (int i=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;
}

我想把奇数行的背景设置为brush0,偶数行背景设置为brush1.
但是有了滚动条后就会出现问题,拖动滚动条后再现的所有行的背景都为brush0了.
偶数行没有设置为brush1
...全文
评论 7
收藏 已收藏
分享
返回顶部
coldplay968
VC/MFC 16,551 成员 421,605 内容