Solved

CListCtrl : row height response to OnSetFont

Posted on 1998-07-23
3
867 Views
Last Modified: 2013-11-20
When changing a font in a CListCtrl derived object, how do I properly adjust the row height ?  I must also be aware that my users could have *any* video mode set...
0
Comment
Question by:softev
3 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
ID: 1319662
You'll need to select the font into the DC and get the font's height when displayed on that DC.
0
 
LVL 1

Author Comment

by:softev
ID: 1319663
More information to clarify the problem:
  - the CListCtrl is ownerdrawn, report mode
  - the font is changed in the CListCtrl using a SetFont() call.
  - I maintain the header font by performing a SetFont()
    separately on on it after the above setfont call
  - I've implemented an :OnSetFont handler to adjust the row
height as such:

    GetWindowRect( &rc );      
    WINDOWPOS wp;      
    wp.hwnd     = m_hWnd;
    wp.cx       = rc.Width();      
    wp.cy       = rc.Height();
    wp.flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER;
    SendMessage( WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp );      
   
and a MeasureItem handler:

      LOGFONT lf;
      GetFont()->GetLogFont( &lf );
      if( lf.lfHeight < 0 )
          lpMeasureItemStruct->itemHeight = (-lf.lfHeight);
      else
              lpMeasureItemStruct->itemHeight = lf.lfHeight;


as was suggested on www.codeguru.com.  The resulting functionality has two problems.
1) the header and listctrl does not repaint correctly upon scrolling the list just after setting a new font.
2) the row height is not always correct under different
resolution/font combinations.

I attempted to implement your suggestion of using the DC.
Using the following code in the MeasureItem handler:

      CDC* pDC = GetDC();
      ASSERT( pDC );
      
      TEXTMETRIC txtMetric;
      pDC->GetTextMetrics( &txtMetric );

    lpMeasureItemStruct->itemHeight = txtMetric.tmHeight;

the result is an insufficient row height size.

0
 
LVL 8

Accepted Solution

by:
Answers2000 earned 100 total points
ID: 1319664
Try changing the list view to one of the other modes (e.g. large icon) and then change in back to details mode.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.

761 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