Solved

CListCtrl : row height response to OnSetFont

Posted on 1998-07-23
3
855 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

772 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now