Solved

Need font used by CListView in report mode so can print columns with same size

Posted on 2000-03-26
4
164 Views
Last Modified: 2013-12-03
I am trying to print information that is held in a CListView in report mode.  I have about 12 - 15 columns that have been sized to the header and text in the column below with a LVSCW_AUTOSIZE_USEHEADER and then the user may have changed the widths of any colunn by moving the header separators.  I want to replicate this column information (not necessarily in the same columns) in fields on the printed output.

I can get the width of each column in pixels from the LV_COLUMN struct but I'm not sure how to get the average number of characters that the column is sized for.  If I could get the font that the list control is using then I could ask text metrics for the average character width and from that get the number of average chacters in each column.  Since I know the printer font, I can size the printer fields to match the list control fields.

Basic question is: How can I ask the system for the font that a list control is using?

Can the user change a list control font?

Do different machines have different list control fonts?
0
Comment
Question by:emitchell
  • 2
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
RONSLOW earned 75 total points
ID: 2659386
Get GetFont() to get the font.
0
 

Author Comment

by:emitchell
ID: 2664349
I tried using GetFont() in the list control.  The sequence was as follows:

    // pick up the actual list control associated with this view
    CListCtrl& rlc = GetListCtrl();

    // get the font for list control window
    CFont* pFont = rlc.GetFont();
    LOGFONT lf;
    int ret = pFont->GetLogFont(&lf);

The LOGFONT struct here has -10 for the lfHeight member and 0 for the lfWidth which is supposed to be the average character width of the font. ie.

      lfHeight      -10
      lfWidth      0
        ...
+      lfFaceName      0x006eeae8 "MS Sans Serif"

I got the above text by highlighting the line in the QuickWatch window and doing Copy/Paste into this doc.

I need the average width so that I can convert the cx from the CListCtrl in pixels to an average number of characters.

0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 2667394
get a DC (GetDC) for the list control and then call GetTextMetrics on in and get the average character width from there.

Or call GetTextExtent with a large string (eg "ABCD...XYZabcd...xyz") and work out average size from that.
0
 

Author Comment

by:emitchell
ID: 2696680
The DC for the ListCtrl does the trick.  The average character width from this works fine.

Thanks to the input.  I'm sorry I have been so long in responding but I was travelling back to the cold North from Florida!
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 …
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 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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

758 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

19 Experts available now in Live!

Get 1:1 Help Now