Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ MFC
Hello,
 
I do want to display multiline text in ListCtrl of Report View Style.
While displaying data, i do want black color grid lines in Reoprt View Style.
 
Anyone can help me out in this?
Posted 3-Mar-10 19:33pm
AJ831.2K
Page 3 of 3

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 44

Try it Smile | :)
 
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; //Any start color
	    int r2=60,g2=88,b2=156; //Any stop color
	    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));
	    }
      // Copying of the result in to the result DC
      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);
      // Draw here the whole content of the cDestRect
      // at the cMemDC, for example:
      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));
      }
      // The row frame
      cMemDC.MoveTo(cRect.left, cRect.bottom);
      cMemDC.LineTo(cRect.right, cRect.bottom);
      cMemDC.LineTo(cRect.right, cRect.top-1);
      
      // The cells frames and textes
      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);
      //...
      // Copying of the result in to the result DC
      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;
      //cItemRect.OffsetRect(0, -cItemRect.top);
      for (int i=0;i<=chunk_height;i++)
      {
	      cMemDC.FillRect(&cItemRect,i %2 ? &brush1 : &brush0);
        cItemRect.OffsetRect(0, cItemRect.Height());
      }
      brush0.DeleteObject();
      brush1.DeleteObject();
      
      // Copying of the result in to the result DC
      pDC->BitBlt(rect.left,
                  rect.top,
                  rect.Width(),
                  rect.Height(),
                  &cMemDC,
                  0,
                  0,
                  SRCCOPY);
      cMemDC.SelectObject(pcOldBitmap);
      cBmp.DeleteObject();
    }
    cMemDC.DeleteDC();
  }
  return true;
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 45

I tried your last given solution but this also not working.
 
Flickering is still on. when i am increasing decreasiing width of CListCtrl or resizing window, i am getting flickering screen.
 
Ohhhhh.. how to get rid of this?Confused | :confused:
 
I also tried many other option with "Erasebkground". but i think we are still missing some logic which can stop flickering like button.
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 30

do you want me to comment pDC of "Erasebkground()".?
 
But i do want this background.
 
Any other suggestion?
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 32

In DrawItem(), pDC->FillSolidRect(), is already commented.
 
I did not get exactly what are you trying to convey.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 33

Yes. But it may not be commented,
you should fill out the rows background with a method... Smile | :)
  Permalink  
Page 3 of 3
1 2 3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 470
1 mhegazy94 460
2 Ravi Bhavnani 190
3 Kornfeld Eliyahu Peter 185
4 Shemeemsha RA 160
0 Sergey Alexandrovich Kryukov 7,135
1 OriginalGriff 6,801
2 CPallini 5,350
3 George Jonsson 3,619
4 Gihan Liyanage 2,797


Advertise | Privacy | Mobile
Web01 | 2.8.140922.1 | Last Updated 6 Mar 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100