Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
Member Area
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Become a Member
-Why sign up!
-Chat Online!
-Indexes NEW!!
-Build your resume
-Find a job
-Post a job
-Resume Search
-Link to us
Visit Embarcadero
Embarcadero Community
How to get the font settings as defined in the Windows display properties Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Delphi 2.x
User Rating
No Votes
# Votes
DSP, Administrator
Reference URL:
			Author: Jonas Bilinkevicius

I'm using a TMenuBar control and I would like my menus to be the same size as 
defined in the Windows display properties. The same goes for the rest of my 
application. How can I find out what the windows settings for fonts and sizes for 
menus are?


1   function GetCaptionFont: TFont;
2   var
3     ncMetrics: TNonClientMetrics;
4   begin
5     ncMetrics.cbSize := sizeof(TNonClientMetrics);
6     SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(TNonClientMetrics), 
7   @ncMetrics,
8       0);
9     Result := TFont.Create;
10    Result.Handle := CreateFontIndirect(ncMetrics.lfCaptionFont);
11  end;

In Windows XP, applications seem to have a concept of a system font. That is, 
labels and captions seem to appear in another font other than MS Sans Serif. I was 
wondering if it is possible to detect this font and use it in Delphi applications. 
Currently, everything seems hard-coded to MS Sans Serif.

12  procedure GetCaptionFont(afont: TFont);
13  var
14    ncMetrics: TNonClientMetrics;
15  begin
16    assert(assigned(afont));
17    ncMetrics.cbSize := sizeof(TNonClientMetrics);
18    SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
19      sizeof(TNonClientMetrics), @ncMetrics, 0);
20    afont.Handle := CreateFontIndirect(ncMetrics.lfCaptionFont);
21  end;

The TNonClientMetrics structure also contains information on other fonts used in 
the non-client area:

lfCaptionFont: Font used in regular captions
lfSmCaptionFont: Font used in small captions
lfMenuFont: Font used in menus
lfStatusFont: Font used in status bars
lfMessageFont: Font used in message boxes

The problem with changing the forms font (and with it all controls that have Parentfont = true) is that it will likely change the size of some controls that autosize depending on fonts, and that can screw up your layout.

Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10


Share this page
Download from Google

Copyright © Mendozi Enterprises LLC