Solved

Get System Font

Posted on 2002-04-09
3
1,974 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
[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
3 Comments
 
LVL 1

Expert Comment

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

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

Industry Leaders: 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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
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…

729 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