Solved

Get System Font

Posted on 2002-04-09
3
1,952 Views
Last Modified: 2013-12-03
How Can I get System Font in Windows (eg.: the one that is used on the taskbar (size, font name, ...)) ?
0
Comment
Question by:rafaelri
3 Comments
 
LVL 1

Expert Comment

by:Alone
ID: 6929241
Try SystemParametersInfo. See help for SPI_GETICONTITLELOGFONT, SPI_GETNONCLIENTMETRICS and NONCLIENTMETRICS structure.
0
 
LVL 33

Accepted Solution

by:
Slick812 earned 38 total points
ID: 6929979
hello rafaelri, I don't think you have the correct term for the font you want. It isn't the "System font", but the active Caption Font. Anyway, here's how to get the handle for the windows System Font,

hSysFont := GetStockObject(SYSTEM_FONT);

the font used in the Taskbar is the active Caption Font and you can get the FontLog for that font from the NonClientMetrics returned with the SystemParametersInfo function. Here is a procedure I have used to get a few of the windows fonts

procedure GetSystemFonts;
var
NonClMetrics: TNonClientMetrics;
TempLogF: TLogFont;
CaptionFont, MenuFont, MessFont, IconFont, StatusFont: THandle;
CapFontHeight: Integer;
CapFontName: String;
begin
NonClMetrics.cbSize := SizeOf(NonClMetrics);
SystemParametersInfo(
    SPI_GETNONCLIENTMETRICS,     // system parameter to query or set
    0,
    @NonClMetrics, // address of NonClientMetrics
    0
   );
{The SystemParametersInfo function queries or sets systemwide parameters
with  SPI_GETNONCLIENTMETRICS  you get the metrics associated with the
standard nonclient area of windows.}

CaptionFont := CreateFontIndirect(NonClMetrics.lfCaptionFont);
CapFontName := String(NonClMetrics.lfCaptionFont.lfFaceName);
CapFontHeight := NonClMetrics.lfCaptionFont.lfHeight;
MenuFont := CreateFontIndirect(NonClMetrics.lfMenuFont);
StatusFont := CreateFontIndirect(NonClMetrics.lfStatusFont);
MessFont := CreateFontIndirect(NonClMetrics.lfMessageFont);

{see API help for index NONCLIENTMETRICS, to see other info in NonClMetrics}
SystemParametersInfo(SPI_GETICONTITLELOGFONT,SizeOf(TempLogF),@TempLogF,0);
{this gets the font used under icons}
IconFont := CreateFontIndirect(TempLogF);
end;

if you want to use these font handles as delphi fonts you can do a handle assignment

Edit1.Font.Handle := CaptionFont;

or
Form1.Canvas.Font.Handle := CaptionFont;

you should DeleteObject when you are finished with the fonts

DeleteObject(CaptionFont);
DeleteObject(MenuFont);


ask questions if it's unclear
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 6930950
This procedure enum all system fonts.

procedure TMainForm.GetFontNames;
var
  DC: HDC;
begin
  DC := GetDC(0);
  EnumFonts(DC, nil, @EnumFontsProc, Pointer(FontName.Items));
  ReleaseDC(0, DC);
  FontName.Sorted := True;
end;
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
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…

813 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now