Click here to Skip to main content
15,119,410 members
Articles / Desktop Programming / MFC
Posted 10 Jul 2001


34 bookmarked

Finding a Font file from a Font name

Rate me:
Please Sign up or sign in to vote.
4.51/5 (19 votes)
10 Jul 2001CPOL3 min read
How to find the name of a font file, given the display name of a font

Sample Image - FontFile.jpg


This topic seems to recycle through news groups every so often, so I thought to share one solution I came up with. The problem is to determine name of an installed font file (e.g., ARIAL.TTF), given display name of a font (e.g., Arial). The solution involves enumerating fonts listed in registry, after first checking Windows OS version.

What it does

The demo FontFileTest project shows how to retrieve font file name from a font's display name (which is name you will see in MS Word font combobox, for example). All Win32 versions of Windows, going back to original Win95, have a directory called "Fonts" under Windows directory. This directory is mirrored in registry under key HKLM\Software\Microsoft\Windows\CurrentVersion\Fonts. Except, of course, under NT, where "Windows" is replaced with "Windows NT".

How to use it

There is only one function that you need to call, GetFontFile. This takes care of checking OS version and enumerating fonts. The prototype looks like this: BOOL GetFontFile(LPCTSTR lpszFontName, CString& strDisplayName, CString& strFontFile). The argument lpszFontName passes in font's display name, and strDisplayName and strFontFile contain font's display name and file name upon successful return.

To integrate this function into your own program, you'll first need to add following files to your project:

  • GetFontFile.cpp
  • GetFontFile.h
  • GetNameValue.cpp
  • GetNameValue.h
  • GetWinVer.cpp
  • GetWinVer.h

Next, include header file GetFontFile.h in module where you want to call GetFontFile function. For an example of how to call GetFontFile, see FontFileTestDlg.cpp in demo project.

This code was built under VC 6.0, and has been tested under Win95, Win98, NT4, and Win2000. One thing to keep in mind is that GetFontFile() tries to match whatever string you pass in via lpszFontName. It doesn't have to be the complete display name. This means that if you call it like this: GetFontFile("a", strName, strFile), it will match the first font in the registry whose display name begins with an "a". Since the fonts in registry are not sorted when you enumerate them (although they appear to be when use Regedit), it is hard to say which font this would be. To see how this works, look at the TRACE output in the debug output window.

Why it may not work for you

Unfortunately, this cannot be considered a 100% effective method for finding name of a font file. If a font has been installed in a normal manner, and if it is in Windows "Font" directory, then this method will probably work. It will probably work for most screen fonts and TrueType fonts. However, this method might not work for fonts that are created or installed dynamically, or that are specific to a particular device, or that are not installed into font directory. I have noticed that on some systems, there are certain fonts that seem to be "hidden", such as "System" font and sometimes "MS Sans Serif" and "MS Serif". Before posting a message or sending me email, please check first to see if font is listed in the registry under key I give above. You have to decide for yourself whether problems I mention here can be lived with.


Thanks to Chris Maunder and all the other people who post here, for wonderful useful source code.


This software is released into the public domain. You are free to use it in any way you like. If you modify it or extend it, please to consider posting new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Hans Dietrich
Software Developer (Senior) Hans Dietrich Software
United States United States
I attended St. Michael's College of the University of Toronto, with the intention of becoming a priest. A friend in the University's Computer Science Department got me interested in programming, and I have been hooked ever since.

Recently, I have moved to Los Angeles where I am doing consulting and development work.

For consulting and custom software development, please see

Comments and Discussions

QuestionFIX for "Access Denied" with Windows 7 Pin
StefanWoe8-May-14 5:09
MemberStefanWoe8-May-14 5:09 
Generalforeign languages Pin
eborger19-Aug-09 5:32
Membereborger19-Aug-09 5:32 
GeneralUseless Pin
kilt1-Dec-08 6:10
Memberkilt1-Dec-08 6:10 
GeneralRe: Useless Pin
Roey C29-Jul-09 10:10
MemberRoey C29-Jul-09 10:10 
QuestionBold/Italic Pin
jgauffin8-Feb-07 22:24
Memberjgauffin8-Feb-07 22:24 
Questionfont engine Pin
Savitha Rao3-Aug-06 2:15
MemberSavitha Rao3-Aug-06 2:15 
GeneralEnumerating all chinese fonts... Pin
LuS711-Jun-06 4:39
MemberLuS711-Jun-06 4:39 
QuestionCan I Have the C# version of the above code Pin
Rangashan5-Oct-05 23:34
MemberRangashan5-Oct-05 23:34 
AnswerRe: Can I Have the C# version of the above code Pin
Mohamed Elzahaby22-Nov-05 9:54
MemberMohamed Elzahaby22-Nov-05 9:54 
QuestionFinding Fonts Pin
Gary Graf31-Aug-05 13:40
MemberGary Graf31-Aug-05 13:40 
AnswerRe: Finding Fonts Pin
mmjjkk12-Nov-07 5:57
Membermmjjkk12-Nov-07 5:57 
GeneralConverted into Pin
Mohamed Elzahaby1-May-05 6:14
MemberMohamed Elzahaby1-May-05 6:14 
Generalworkdir and fonts Pin
Anonymous5-Apr-04 22:59
MemberAnonymous5-Apr-04 22:59 
GeneralSame on Solaris Pin
Member 1817630-Oct-02 19:03
MemberMember 1817630-Oct-02 19:03 
GeneralReverse lookup Pin
axiac18-Feb-02 6:42
Memberaxiac18-Feb-02 6:42 
GeneralRe: Reverse lookup Pin
Hans Dietrich18-Feb-02 23:06
mentorHans Dietrich18-Feb-02 23:06 
GeneralRe: Reverse lookup Pin
Philip Patrick17-May-02 14:06
professionalPhilip Patrick17-May-02 14:06 
Generala bug Pin
28-Sep-01 16:05
suss28-Sep-01 16:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.