Solved

How to get font size of your system?

Posted on 1998-08-31
9
218 Views
Last Modified: 2013-12-03
Any API call can give me the font size of my system? Font size you get when you click right mouse button on your screen and then select properties and then select setting tab.
0
Comment
Question by:ames
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 7

Accepted Solution

by:
psdavis earned 100 total points
Comment Utility
I believe it's

CDC::GetDeviceCaps( LOGPIXELSX );

It should return either 96 (normal) or 120 (large).


(if not logpixelsx, tell me, I got it somewhere)

Phillip
0
 
LVL 2

Expert Comment

by:jstolan
Comment Utility
I don't believe psdavis is correct.  No GetDeviceCaps function will tell you the system font size.  One way to do it is to get a screen compatible display context using CreateDC.  Then get the system font using GetStockObject(SYSTEMFONT).  Load the font into the CDC using SelectObject.  Finally, you can use the GetTextMetrics call to determine any information you need, including the size.  Don't forget to free up everything correctly.
0
 
LVL 6

Expert Comment

by:snoegler
Comment Utility
The settings you need are stored in the registry:

1. Fetch the current configuration profile, stored here:

HKLM\System\CurrentControlSet\IDConfigDB\CurrentConfig

The value you get there is something like '0001'.

2. Using this value, the display dpi settings are stored here:

HKLM\Config\[ccfg]\Display\Settings
// [ccfg] <-- contains the value from [1]

The value names are:
DPILogicalX, DPILogicalY and
DPIPhysicalX, DPIPhysicalY

But i believe that psdavis is right. The way he proposed should deliver correct values, and
it doesn't depend on the registry.
BTW: The dpi settings *do* contain the system font size - as they tell how to scale the fonts.
0
 
LVL 7

Expert Comment

by:psdavis
Comment Utility
Thanks snoeg!
0
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

 
LVL 23

Expert Comment

by:chensu
Comment Utility
psdavis is correct. A complete version is:

CDC DispDC;
DispDC.CreateIC("DISPLAY", NULL, NULL, NULL);
int nLogDPIX = DispDC.GetDeviceCaps(LOGPIXELSX),
    nLogDPIY = DispDC.GetDeviceCaps(LOGPIXELSY);

// if (nLogDPIX == 96 && nLogDPIY == 96) // small fonts
// if (nLogDPIX == 120 && nLogDPIY == 120) // large fonts
// otherwise, custom font size

0
 
LVL 8

Expert Comment

by:Answers2000
Comment Utility
Well there's an easier way to get all font attributes

LOGFONT lf ;
GetObject( GetStockObject(SYSTEM_FONT), sizeof lf, &lf ) ;

*All* the font attributes are then in lf.
0
 
LVL 8

Expert Comment

by:Answers2000
Comment Utility
Sorry that was SDK, add casts and ::
0
 

Author Comment

by:ames
Comment Utility
psdavis was right. Snoegler's answer with registry works only for 95. For NT the entries are in different location. jstolan's answer may work, but I did not try it. Chensu, as always, makes it easier by providing a complete version. Thanks to you all.
0
 

Author Comment

by:ames
Comment Utility
PSDavis was right. Chensu, as always, makes it easier by providing complete solution. I did not try Jstolan's solution. Snoegler's solution works for 95. It means that you need to check for OS and then read different registry location based on OS. I used Chensu's solution and it works fine. Thanks to you all.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

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…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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…

771 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

11 Experts available now in Live!

Get 1:1 Help Now