Solved

How to get font size of your system?

Posted on 1998-08-31
9
228 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
ID: 1321535
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
ID: 1321536
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
ID: 1321537
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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

 
LVL 7

Expert Comment

by:psdavis
ID: 1321538
Thanks snoeg!
0
 
LVL 23

Expert Comment

by:chensu
ID: 1321539
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
ID: 1321540
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
ID: 1321541
Sorry that was SDK, add casts and ::
0
 

Author Comment

by:ames
ID: 1321542
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
ID: 1321543
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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…

790 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