Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to get font size of your system?

Posted on 1998-08-31
9
Medium Priority
?
239 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 400 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses

670 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