AddFontResourceW function (wingdi.h)

The AddFontResource function adds the font resource from the specified file to the system font table. The font can subsequently be used for text output by any application.

To mark a font as private or not enumerable, use the AddFontResourceEx function.

Syntax

int AddFontResourceW(
  [in] LPCWSTR unnamedParam1
);

Parameters

[in] unnamedParam1

A pointer to a null-terminated character string that contains a valid font file name. This parameter can specify any of the following files.

File Extension Meaning
.fon
Font resource file.
.fnt
Raw bitmap font file.
.ttf
Raw TrueType file.
.ttc
East Asian Windows: TrueType font collection.
.fot
TrueType resource file.
.otf
PostScript OpenType font.
.mmm
Multiple master Type1 font resource file. It must be used with .pfm and .pfb files.
.pfb
Type 1 font bits file. It is used with a .pfm file.
.pfm
Type 1 font metrics file. It is used with a .pfb file.
 

To add a font whose information comes from several resource files, have lpszFileName point to a string with the file names separated by a "|" --for example, abcxxxxx.pfm | abcxxxxx.pfb.

Return value

If the function succeeds, the return value specifies the number of fonts added.

If the function fails, the return value is zero. No extended error information is available.

Remarks

Any application that adds or removes fonts from the system font table should notify other windows of the change by sending a WM_FONTCHANGE message to all top-level windows in the operating system. The application should send this message by calling the SendMessage function and setting the hwnd parameter to HWND_BROADCAST.

When an application no longer needs a font resource that it loaded by calling the AddFontResource function, it must remove that resource by calling the RemoveFontResource function.

This function installs the font only for the current session. When the system restarts, the font will not be present. To have the font installed even after restarting the system, the font must be listed in the registry.

A font listed in the registry and installed to a location other than the %windir%\fonts\ folder cannot be modified, deleted, or replaced as long as it is loaded in any session. In order to change one of these fonts, it must first be removed by calling RemoveFontResource, removed from the font registry (HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts), and the system restarted. After restarting the system, the font will no longer be loaded and can be changed.

Note

The wingdi.h header defines AddFontResource as an alias that automatically selects the ANSI or Unicode version of this function based on the definition of the UNICODE preprocessor constant. Mixing usage of the encoding-neutral alias with code that is not encoding-neutral can lead to mismatches that result in compilation or runtime errors. For more information, see Conventions for Function Prototypes.

Requirements

Requirement Value
Minimum supported client Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header wingdi.h (include Windows.h)
Library Gdi32.lib
DLL Gdi32.dll

See also

AddFontResourceEx

Font and Text Functions

Fonts and Text Overview

RemoveFontResource

SendMessage