Try it :)
BOOL CListForm::OnEraseBkgnd(CDC* pDC)
{
CDC cMemDC;
if (cMemDC.CreateCompatibleDC(pDC)) {
CBitmap cBmp;
CRect rect;
GetClientRect(&rect);
if (cBmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height())) {
CGdiObject* pcOldBitmap = cMemDC.SelectObject(&cBmp);
int r1=19,g1=40,b1=85;
int r2=60,g2=88,b2=156;
for(int i=0;i<rect.Height();i++)
{
int r,g,b;
r = r1 + (i * (r2-r1) / rect.Height());
g = g1 + (i * (g2-g1) / rect.Height());
b = b1 + (i * (b2-b1) / rect.Height());
cMemDC.FillSolidRect(0,i,rect.Width(),1,RGB(r,g,b));
}
pDC->BitBlt(rect.left,
rect.top,
rect.Width(),
rect.Height(),
&cMemDC,
0,
0,
SRCCOPY);
cMemDC.SelectObject(pcOldBitmap);
cBmp.DeleteObject();
}
cMemDC.DeleteDC();
}
return true;
}
void CColoredListReport::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
switch (lpDrawItemStruct->itemAction) {
case ODA_DRAWENTIRE:
DrawEntry(pDC,
CRect(lpDrawItemStruct->rcItem),
lpDrawItemStruct->itemID);
break;
}
}
void CColoredListReport::DrawEntry(CDC* pdcDestDC,
const CRect& cDestRect,
int iItem)
{
CDC cMemDC;
if (cMemDC.CreateCompatibleDC(pdcDestDC)) {
CBitmap cBmp;
if (cBmp.CreateCompatibleBitmap(pdcDestDC, cDestRect.Width(), cDestRect.Height())) {
CGdiObject* pcOldBitmap = cMemDC.SelectObject(&cBmp);
CRect cRect(0, 0, cDestRect.right, cDestRect.bottom);
cRect.DeflateRect(0, 0, 1, 1);
if (iItem % 2 == 0) {
cMemDC.FillSolidRect(cRect, RGB(213, 220, 239));
} else {
cMemDC.FillSolidRect(cRect, RGB(255, 255, 255));
}
cMemDC.MoveTo(cRect.left, cRect.bottom);
cMemDC.LineTo(cRect.right, cRect.bottom);
cMemDC.LineTo(cRect.right, cRect.top-1);
CRect cSubItemRect;
GetSubItemRect(iItem, 0, LVIR_LABEL, cSubItemRect);
cSubItemRect.OffsetRect(0, -cSubItemRect.top);
cMemDC.DrawText(GetItemText(iItem, 0), cSubItemRect, DT_LEFT);
GetSubItemRect(iItem, 1, LVIR_LABEL, cSubItemRect);
cSubItemRect.OffsetRect(0, -cSubItemRect.top);
cMemDC.MoveTo(cSubItemRect.TopLeft());
cMemDC.LineTo(cSubItemRect.left, cSubItemRect.bottom);
cMemDC.DrawText(GetItemText(iItem, 1), cSubItemRect, DT_CENTER|DT_VCENTER);
GetSubItemRect(iItem, 2, LVIR_LABEL, cSubItemRect);
cSubItemRect.OffsetRect(0, -cSubItemRect.top);
cMemDC.MoveTo(cSubItemRect.TopLeft());
cMemDC.LineTo(cSubItemRect.left, cSubItemRect.bottom);
cMemDC.DrawText(GetItemText(iItem, 2), cSubItemRect, DT_CENTER|DT_VCENTER);
GetSubItemRect(iItem, 3, LVIR_LABEL, cSubItemRect);
cSubItemRect.OffsetRect(0, -cSubItemRect.top);
cMemDC.MoveTo(cSubItemRect.TopLeft());
cMemDC.LineTo(cSubItemRect.left, cSubItemRect.bottom);
cMemDC.DrawText(GetItemText(iItem, 3), cSubItemRect, DT_LEFT | DT_WORDBREAK);
pdcDestDC->BitBlt(cDestRect.left,
cDestRect.top,
cDestRect.Width(),
cDestRect.Height(),
&cMemDC,
0,
0,
SRCCOPY);
cMemDC.SelectObject(pcOldBitmap);
cBmp.DeleteObject();
}
cMemDC.DeleteDC();
}
}
BOOL CColoredListReport::OnEraseBkgnd(CDC* pDC)
{
CRect rect;
CColoredListReport::GetClientRect(rect);
CDC cMemDC;
if (cMemDC.CreateCompatibleDC(pDC)) {
CBitmap cBmp;
if (cBmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height())) {
CGdiObject* pcOldBitmap = cMemDC.SelectObject(&cBmp);
CBrush brush0(m_colRow1);
CBrush brush1(m_colRow2);
int chunk_height=GetCountPerPage();
cMemDC.FillRect(&rect,&brush1);
CRect cItemRect(rect);
GetItemRect(0, cItemRect, LVIR_BOUNDS);
cItemRect.left = rect.left;
cItemRect.right = rect.right;
for (int i=0;i<=chunk_height;i++)
{
cMemDC.FillRect(&cItemRect,i %2 ? &brush1 : &brush0);
cItemRect.OffsetRect(0, cItemRect.Height());
}
brush0.DeleteObject();
brush1.DeleteObject();
pDC->BitBlt(rect.left,
rect.top,
rect.Width(),
rect.Height(),
&cMemDC,
0,
0,
SRCCOPY);
cMemDC.SelectObject(pcOldBitmap);
cBmp.DeleteObject();
}
cMemDC.DeleteDC();
}
return true;
}