?
Solved

Changing rowsheight in CListCtrl

Posted on 2002-07-18
6
Medium Priority
?
501 Views
Last Modified: 2013-11-20
Hi All,
I tried to change font size of CListCtrl object. Unfortunately the row height of the control was not updated, and the text got clipped. I tried to run my app on win 98 as well as win NT.

Any suggestions?

p.s.
Please, Real answares. Not links to codeguru or codeproject

--EC--
0
Comment
Question by:elcapitan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
6 Comments
 
LVL 30

Expert Comment

by:SteveGTR
ID: 7162062
Sorry for the "unreal" answer:

http://www.codeproject.com/listctrl/changerowheight.asp

You're going to have to a little reading :)


0
 
LVL 3

Author Comment

by:elcapitan
ID: 7162088
This article is dealing with owner draw controls. I'm not interesting in drawing the control my self. Is there another way to do that? maybe custom draw?
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 7162131
Use the techniques decribed for WM_MEASUREITEM. I briefly tried out the technique using the dialog's message mapping and it worked fine:

BEGIN_MESSAGE_MAP(CGrantBrowse, CAuxiliaryDialog)
  // ...
  ON_WM_MEASUREITEM()
  // ...
END_MESSAGE_MAP()

void CMyDlg::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
  if (nIDCtl == IDC_MYLISTCTRL)
    lpMeasureItemStruct->itemHeight = 20;
  else
    CDialog::OnMeasureItem(nIDCtl, lpMeasureItemStruct);
}

There appears to be a way to redirect the measure item message using reflection so that the subclassed control is more usable. Rather than relying on the container window having to resize the control's height.

Good Luck,
Steve

0
 
LVL 30

Accepted Solution

by:
SteveGTR earned 1200 total points
ID: 7163119
Of course the example I plugged the above into was for a ownerdrawn list control. Here is a draw handler from the class I tested with. It is based on CSortListCtrl from MSJ "Wicked code" column from 12/97 Vol 11, No 12:
 
// To allow for row highlighting you must check the "Owner drawn fixed" attribute
// in the CListCtrl's properties.
void CSortListCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
      static BOOL bClearing=FALSE;

      // Get the display context for the control.
      CDC* pCDC = CDC::FromHandle(lpDrawItemStruct->hDC);

      // Use mask if there is one.
      UINT uiFlags(ILD_TRANSPARENT);

      // Check to see if this item is selected.
      if (lpDrawItemStruct->itemState & ODS_SELECTED)
            {
            pCDC->SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));
            pCDC->SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));
            uiFlags |= ILD_BLEND50;
            }
      else
            {
            pCDC->SetTextColor(::GetSysColor(COLOR_WINDOWTEXT));
            pCDC->SetBkColor(::GetSysColor(COLOR_WINDOW));
            }

      // Get the image list and draw.
      CImageList* plistImages = GetImageList(LVSIL_SMALL);

      // In order to get the focus rectangle to disappear on highlighted rows,
      // I had to force an invalidate via this cheesey methold. Not doing so
      // would cause the only the 1st column to be repainted with the border!
      if (lpDrawItemStruct->itemState & ODS_FOCUS)
            {
            if (!bClearing)
                  {
                  bClearing = TRUE;
          CRect rTextClip(lpDrawItemStruct->rcItem);
                  rTextClip.left += (plistImages ? 16 : 0);

                  InvalidateRect(rTextClip);
                  return;
                  }
            else
                  bClearing = FALSE;
            }

      // Get the item image to be displayed.
      LV_ITEM lvi;
      memset(&lvi, 0, sizeof(&lvi));
      lvi.mask = LVIF_IMAGE | LVIF_STATE;
      lvi.iItem = lpDrawItemStruct->itemID;
      GetItem(&lvi);

      // If valid, draw.
      if (plistImages)
            {
            CPoint ptAt(lpDrawItemStruct->rcItem.left, lpDrawItemStruct->rcItem.top);
                  plistImages->Draw(pCDC, lvi.iImage, ptAt, uiFlags);
            }

      // Now walk through columns and draw text.
      char szText[256];     // Increase this if you have longer text.
      LV_COLUMN lvc;
      memset(&lvc, 0, sizeof(lvc));
      lvc.mask = LVCF_WIDTH;

      for (int nColumn = 0; GetColumn(nColumn, &lvc); nColumn++)
            {
            CRect rTextClip;

            // First time.
            if (0 == nColumn)
                  {
                  rTextClip.left   = lpDrawItemStruct->rcItem.left + (plistImages ? 16 : 0);
                  rTextClip.top    = lpDrawItemStruct->rcItem.top;
                  rTextClip.right  = lpDrawItemStruct->rcItem.left + lvc.cx;
                  rTextClip.bottom = lpDrawItemStruct->rcItem.bottom;
                  }
            else
                  {
                  // Just "move" the rect to the right.
                  rTextClip.left  = rTextClip.right;
                  rTextClip.right = rTextClip.left + lvc.cx;
                  }

            // Get the text.
            lvi.iItem = lpDrawItemStruct->itemID;
            lvi.mask = LVIF_TEXT;
            lvi.iSubItem = nColumn;
            lvi.pszText = szText;
            lvi.cchTextMax = sizeof(szText);
            GetItem(&lvi);

            // Add ellipses if necessary.
            int nTextCount(lstrlen(lvi.pszText));

            CSize sizText(pCDC->GetOutputTextExtent(lvi.pszText, nTextCount));

            // Make the clipping rectangle a little smaller for a gap
            // effect between columns.
            rTextClip.right -= 4;

            if (sizText.cx >= rTextClip.Width())
                  {
                  // Make a shorter string, including "..." that fits.
                  CSize sizEllipse = pCDC->GetOutputTextExtent("...", 3);

                  // Now start dropping characters at the tail until width
                  // is correct.
                  while (sizText.cx+sizEllipse.cx > (rTextClip.Width()) && nTextCount > 1)
                        {
                        lvi.pszText[--nTextCount] = 0;
                        sizText = pCDC->GetOutputTextExtent(lvi.pszText, nTextCount);
                        }

                  // Ok, append "...".
                  lvi.pszText[nTextCount] = '.';
                  lvi.pszText[nTextCount + 1] = '.';
                  lvi.pszText[nTextCount + 2] = '.';
                  lvi.pszText[nTextCount + 3] = 0;
                  }

            // Restore full rect.
            rTextClip.right += 4;

            // Print the text.
            pCDC->ExtTextOut(rTextClip.left + 2, rTextClip.top + 1,
                  ETO_CLIPPED | ETO_OPAQUE, &rTextClip, lvi.pszText, lstrlen(lvi.pszText), NULL);
        }

      // If focused draw focus rect (I added the focus check)
      if (lpDrawItemStruct->itemState & ODS_FOCUS)
            {
    CRect rTextClip(lpDrawItemStruct->rcItem);
            rTextClip.left += (plistImages ? 16 : 0);

            CWnd *pFocusWnd = GetFocus();
            
            if (pFocusWnd && pFocusWnd->m_hWnd == m_hWnd)
                  pCDC->DrawFocusRect(rTextClip);
            else
                  {
                  CBrush bdrBrush(::GetSysColor(COLOR_HIGHLIGHT));
                  pCDC->FrameRect(rTextClip, &bdrBrush);
                  }
            }

      // Reset colors if necessary.
      if (lpDrawItemStruct->itemState & ODS_SELECTED)
            {
            pCDC->SetTextColor(::GetSysColor(COLOR_WINDOWTEXT));
            pCDC->SetBkColor(::GetSysColor(COLOR_WINDOW));
            }
}
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month11 days, 18 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question