Solved

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

Posted on 2000-03-26
4
167 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Set Font and Size on Excel Template 2 120
Fibonacci challenge 11 133
Trying to run powershell  in a batch file. How do I do this? 8 106
GET error with Font Awesome 3 16
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…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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…

828 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