Solved

CListCtrl : row height response to OnSetFont

Posted on 1998-07-23
3
870 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
[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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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 …
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.
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

734 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