Solved

CListCtrl : row height response to OnSetFont

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
function returning CString in a regular win32 DLL 8 178
repeateFront java challenge 31 93
wordappend challenge 8 181
Problem to App 4 83
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…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

832 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