Solved

How to get font size of your system?

Posted on 1998-08-31
9
234 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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…

739 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