Solved

CListCtrl : row height response to OnSetFont

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

 Watch the Recording: Learning MySQL 5.7

MySQL 5.7 has a lot of new features. If you've dabbled with an older version of MySQL, it is definitely worth learning.

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

622 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