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
Solved

Changing rowsheight in CListCtrl

Posted on 2002-07-18
6
490 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
  • 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 300 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
Turn a spreadsheet into a vba executable. 2 93
How to determine file rename from EventLog ? 2 54
withoutTen challenge 14 131
firstChar challenge 13 121
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

856 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