Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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

Page 3 of 3


Please try it :) :
void DrawSomething(CDC* pdcDestDC, const CRect& cDestRect)
{
  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:
      cMemDC.MoveTo(0, 0);
      cMemDC.LineTo(100, 100);
      //...
      // Copying of the result in to the destination DC
      pdcDestDC->BitBlt(cDestRect.left,
                        cDestRect.top,
                        cDestRect.Width(),
                        cDestRect.Height(),
                        &cMemDC,
                        0,
                        0,
                        SRCCOPY);
      cMemDC.SelectObject(pcOldBitmap);
      cBmp.DeleteObject();
    }
    cMemDC.DeleteDC();
  }
}

We do not need any region setting here :)
 
Share this answer
 
How to use this function in my class.

my drawitem is as below:
void CColoredListReport::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
	// TODO:  Add your code to draw the specified item
	CDC* pDC = CDC::FromHandle(lpDrawItemStruct->hDC);
	
	switch (lpDrawItemStruct->itemAction)
	{
		case ODA_DRAWENTIRE:
			CRect cRect(lpDrawItemStruct->rcItem);
			cRect.DeflateRect(0, 0, 1, 1);
			if (lpDrawItemStruct->itemID % 2 == 0)
			{
				pDC->FillSolidRect(cRect, RGB(213, 220, 239));
			}
			else
			{
				pDC->FillSolidRect(cRect, RGB(255, 255, 255));
			}
			// The row frame
			pDC->MoveTo(cRect.left, cRect.bottom);
			pDC->LineTo(cRect.right, cRect.bottom);
			pDC->LineTo(cRect.right, cRect.top-1);
	    
			// The cells frames and textes
			CRect cSubItemRect;
			GetSubItemRect(lpDrawItemStruct->itemID, 0, LVIR_LABEL, cSubItemRect);
			pDC->DrawText(GetItemText(lpDrawItemStruct->itemID, 0), cSubItemRect, DT_LEFT);
			GetSubItemRect(lpDrawItemStruct->itemID, 1, LVIR_LABEL, cSubItemRect);
			pDC->MoveTo(cSubItemRect.TopLeft());
			pDC->LineTo(cSubItemRect.left, cSubItemRect.bottom);
			pDC->DrawText(GetItemText(lpDrawItemStruct->itemID, 1), cSubItemRect, DT_CENTER|DT_VCENTER);
			GetSubItemRect(lpDrawItemStruct->itemID, 2, LVIR_LABEL, cSubItemRect);
			pDC->MoveTo(cSubItemRect.TopLeft());
			pDC->LineTo(cSubItemRect.left, cSubItemRect.bottom);
			pDC->DrawText(GetItemText(lpDrawItemStruct->itemID, 2), cSubItemRect, DT_CENTER|DT_VCENTER);
			lpDrawItemStruct->rcItem.top = (lpDrawItemStruct->rcItem.bottom - lpDrawItemStruct->rcItem.top)/2;
			GetSubItemRect(lpDrawItemStruct->itemID, 3, LVIR_LABEL, cSubItemRect);
			pDC->MoveTo(cSubItemRect.TopLeft());
			pDC->LineTo(cSubItemRect.left, cSubItemRect.bottom);
			pDC->DrawText(GetItemText(lpDrawItemStruct->itemID, 3), cSubItemRect, DT_LEFT | DT_WORDBREAK);
			break;
	}
}
 
Share this answer
 
I used your given idea but it is giving same problem, whole listctrl is having black background.
 
Share this answer
 
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; //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;
}
 
Share this answer
 
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:

I also tried many other option with "Erasebkground". but i think we are still missing some logic which can stop flickering like button.
 
Share this answer
 
v2

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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900