EnumFontFamiliesEx
A version of this page is also available for
4/8/2010
This function enumerates all fonts in the system that match the font characteristics specified by the LOGFONT structure. EnumFontFamiliesEx enumerates fonts based on typeface name, character set, or both.
Syntax
int EnumFontFamiliesEx(
HDC hdc, // handle to DC
LPLOGFONT lpLogfont, // font information
FONTENUMPROC lpEnumFontFamExProc, // callback function
LPARAM lParam, // additional data
DWORD dwFlags // not used; must be 0
);
Parameters
- hdc
[in] Handle to the device context.
lpLogfont
[in] Pointer to a LOGFONT structure that contains information about the fonts to enumerate. The function examines the following members.Member Description lfCharset
If set to DEFAULT_CHARSET, the function enumerates all fonts in all character sets. If set to a valid character set value, the function enumerates only fonts in the specified character set.
lfFaceName
If set to an empty string, the function enumerates one font in each available typeface name. If set to a valid typeface name, the function enumerates all fonts with the specified name.
lfPitchAndFamily
Must be set to zero for all language versions of the operating system.
- lpEnumFontFamExProc
[in] Pointer to the application defined callback function. The callback function is used to process the fonts and is called once for each enumerated font.
- lParam
[in] Specifies an application defined value. The function passes this value to the callback function along with font information.
- dwFlags
This parameter is not used and must be zero.
Return Value
The return value is the last value returned by the callback function. This value depends on which font families are available for the specified device.
Remarks
The EnumFontFamiliesEx function does not use tagged typeface names to identify character sets. Instead, it always passes the correct typeface name and a separate character set value to the callback function. The function enumerates fonts based on the values of the lfCharset and lfFacename members in the LOGFONT structure.
As with EnumFontFamilies, EnumFontFamiliesEx enumerates all font styles. Not all styles of a font cover the same character sets. For example, Fontorama Bold might contain ANSI, Greek, and Cyrillic characters, but Fontorama Italic might contain only ANSI characters. For this reason, it is best not to assume that a specified font covers a specific character set, even if it is the ANSI character set. The following table shows the results of various combinations of values for lfCharSet and lfFaceName.
Values | Meaning |
---|---|
lfCharSet = DEFAULT_CHARSETlfFaceName = '\0' |
Enumerates all fonts in all character sets. |
lfCharSet = DEFAULT_CHARSETlfFaceName = a specific font |
Enumerates all character sets and styles in a specific font. |
lfCharSet =a specific character setlfFaceName = '\0' |
Enumerates all styles of all fonts in the specific character set. |
lfCharSet =a specific character setlfFaceName = a specific font |
Enumerates all styles of a font in a specific character set. |
The following code sample shows how these values are used.
//To enumerate all styles and charsets of all fonts:
lf.lfFaceName[0] = '\0';
lf.lfCharSet = DEFAULT_CHARSET;
HRESULT hr;
//To enumerate all styles and character sets of the Arial font:
hr = StringCchCopy( (LPSTR)&lf.lfFaceName, 6, "Arial" );
if (FAILED(hr))
{
// TODO: write error handler
}
lf.lfCharSet = DEFAULT_CHARSET;
//To enumerate all styles of all fonts for the ANSI character set:
lf.lfFaceName[0] = '\0';
lf.lfCharSet = ANSI_CHARSET;
//To enumerate all styles of Arial font that cover the ANSI charset:
hr = StringCchCopy( (LPSTR)&lf.lfFaceName, 6, "Arial" );
if (FAILED(hr))
{
// Handle errors appropriately
}
lf.lfCharSet = ANSI_CHARSET;
The callback functions for EnumFontFamilies and EnumFontFamiliesEx are very similar.
Based on the values of lfCharSet and lfFaceName, EnumFontFamiliesEx will enumerate the same font as many times as there are distinct character sets in the font. This can create an extensive list of fonts that can be burdensome to a user. For example, the Century Schoolbook font can appear for the Baltic, Western, Greek, Turkish, and Cyrillic character sets. To avoid this, an application should filter the list of fonts.
The fonts for many East Asian languages have two typeface names: an English name and a localized name. EnumFonts, EnumFontFamilies, and EnumFontFamiliesEx return the English typeface name if the system locale does not match the language of the font.
Requirements
Header | wingdi.h |
Library | coredll.lib |
Windows Embedded CE | Windows CE 5.0 and later |
Windows Mobile | Pocket PC for Windows Mobile Version 5.0 and later, Smartphone for Windows Mobile Version 5.0 and later |
See Also
Reference
EnumFonts
EnumFontFamilies
LOGFONT