Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Get System Font

Posted on 2002-04-09
3
Medium Priority
?
2,023 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 34

Accepted Solution

by:
Slick812 earned 152 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
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…
Suggested Courses

877 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