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?
Answer:
1 function GetCaptionFont: TFont;
2 var3 ncMetrics: TNonClientMetrics;
4 begin5 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 var14 ncMetrics: TNonClientMetrics;
15 begin16 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.