Adding a Font Resource

GDI keeps a system font table that contains all the fonts that applications can use. GDI chooses a font from this table when an application makes a request for a font by using the CreateFont function.

A font resource is a group of individual fonts representing characters in a given character set that have various combinations of heights, widths, and pitches. For example, the system font resource contains a collection of fonts representing different sizes of characters in the ANSI character set. Similarly, the OEM font resource contains a collection of fonts representing different sizes of characters in an OEM character set.

An application can have up to 253 entries in the system font table.

Applications can load font resources and add the fonts in the resource to the system font table by using the AddFontResource function. Once a font resource is added, the individual fonts in the resource are accessible to the application. In other words, the CreateFont function considers the fonts when it tries to match a physical font with the specified logical font. (Fonts in the system font table are never directly accessible to an application. They are available only through the CreateFontIndirect and CreateFont functions, which return handles to the fonts, not memory addresses.)

You can add a font resource to the system font table by using the AddFontResource function. Similarly, to make room for other font resources, you can remove a font resource from the system font table by using the RemoveFontResource function.

Whenever an application adds or removes a font resource, it should inform all other applications of the change by sending a WM_FONTCHANGE message to them. You can use the following call to the SendMessage function to send the message to all windows:

SendMessage(-1, WM_FONTCHANGE, 0, 0L);

If the user has installed fonts by using the Control Panel application, you can retrieve a list of those fonts by using the GetProfileString function to search the [fonts] section of the WIN.INI file.