Click here to Skip to main content
Licence 
First Posted 25 Oct 2002
Views 76,130
Bookmarked 23 times

Detecting the Display Font Size

By | 25 Oct 2002 | Article
Simple function to enable you to programmatically detect the user-selected font at runtime.

Introduction

As you've probably seen, the end-user can specify their Font Size to be "Small Fonts", "Large Fonts" or "Custom Font" via the Control Panel's Display applet (Figure 1 below). Since this setting could adversely affect an application's user interface (UI), there are many times in more advanced applications where the knowledge of which setting has been chosen by the user would be useful. For example, this information can be used in determining which dialog to present (if you wanted to present a tailor-made dialog for each font size). In addition, knowing the currently selected font size could be used to give your application's end-user a warning had the UI been designed with only smaller fonts in mind. Whatever your need, this handly little function will assist you in programmatically determining the selected font size.

Font Size of Display Properties
Figure 1 - Sometimes the end-user's choice of font size can wreak havoc with a carefully designed UI.

Function to Detect Font Size

The following code demonstrates how to detect it.
CDC ScreenDC;
VERIFY(ScreenDC.CreateIC(_T("DISPLAY"), NULL, NULL, NULL));
const int nLogDPIX = ScreenDC.GetDeviceCaps(LOGPIXELSX),
          nLogDPIY = ScreenDC.GetDeviceCaps(LOGPIXELSY);

if (nLogDPIX == 96 && nLogDPIY == 96)
{
    // 96 DPI, Small Fonts
}
else
{
    if (nLogDPIX == 120 && nLogDPIY == 120)
    {
        // 120 DPI, Large Fonts
    }
    else
    {
        // Otherwise, Custom Font Size
    }
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Chen Su

Software Developer

Canada Canada

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralMy vote of 1 PinmemberTuan Dang5:05 26 Jun '09  
GeneralFor C# PinmemberChizik22:38 16 Feb '09  
GeneralRe: For C# PinmemberChen Su8:58 17 Feb '09  
GeneralRe: For C# PinmemberChen Su17:38 17 Feb '09  
GeneralRe: For C# PinmemberChizik22:45 17 Feb '09  
Generalfonts PinmemberDaúde Dulla14:38 25 Jan '05  
GeneralRe: fonts PinmemberChen Su19:50 25 Jan '05  
GeneralWhy this doesn't always work.... from MS... Pinmemberkaladorn9:51 14 Oct '04  
QuestionHow to find font size if i have TEXTMETRIC of CDC with me????? Pinmembervinubhai23:38 26 Apr '04  
GeneralDoesn't work in XP PinmemberNavin8:01 14 Jul '03  
GeneralRe: Doesn't work in XP PinmemberChen Su13:23 14 Jul '03  
GeneralRe: Doesn't work in XP PinmemberNavin2:59 15 Jul '03  
GeneralRe: Doesn't work in XP PinmemberChen Su6:59 15 Jul '03  
GeneralRe: Doesn't work in XP PinmemberNavin8:56 15 Jul '03  
GeneralRe: Doesn't work in XP PinmemberClifford T. Hall10:19 3 Oct '03  
GeneralRe: Doesn't work in XP PinmemberTuan Dang10:14 26 Jun '09  
QuestionHow to edit the program to set the display font size? PinmemberFuji Chuang21:45 18 Feb '03  
Questionhow to force a CDialog to normal PinmemberNic Wilson19:50 22 Jan '03  
AnswerRe: how to force a CDialog to normal PinmemberChen Su20:09 22 Jan '03  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 26 Oct 2002
Article Copyright 2002 by Chen Su
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid