EnumFontFamiliesEx

EnumFontFamiliesEx allows you to enumerate fonts based on typeface name and charset. Instead of passing a pointer to a typeface name, you pass a pointer to a logfont structure, which contains the typeface name and charset information.

LOGFONT lf;

lstrcpy( (LPSTR)&lf.lfFaceName, lpsz );
lf.lfCharSet = iCharset;
rc = EnumFontFamiliesEx( hdc, &lf, lpEnumProc, NULL, 0 );

To call EnumFontFamiliesEx, you can either specify a typeface name or a charset, or you can ask for whatever is available. Setting the typeface name of the logfont to NULL enumerates all typeface names. Setting the charset field to DEFAULT_CHARSET enumerates all charsets. As with EnumFontFamilies, EnumFontFamiliesEx enumerates all font styles. Not all styles of the same font cover the same charsets. For example, Fontorama Bold might contain ANSI, Greek, and Cyrillic characters, but Fontorama Italic might contain only ANSI characters. For this reason, never assume that a given font covers a specific charset—even the ANSI charset. If you are not certain about the properties of the available fonts, don't make assumptions. Enumerate the available fonts using the DEFAULT_CHARSET constant. When you do, EnumFontFamiliesEx will separately enumerate each charset range covered by a big font.

// To enumerate all styles and charsets of all fonts:
lf.lfFaceName[0] = '\0';
lf.lfCharSet = DEFAULT_CHARSET;

// To enumerate all styles and charsets of the Arial font:
lstrcpy( (LPSTR)&lf.lfFaceName, "Arial" );
lf.lfCharSet = DEFAULT_CHARSET;

// To enumerate all styles of all fonts that cover the ANSI charset:
lf.lfFaceName[0] = '\0';
lf.lfCharSet = ANSI_CHARSET;

// To enumerate all styles of the Arial font that cover the ANSI
// charset:
lstrcpy( (LPSTR)&lf.lfFaceName, "Arial" );
lf.lfCharSet = ANSI_CHARSET;

As with the API calls themselves, the callback functions for EnumFontFamiliesEx and EnumFontFamilies are very similar. The main difference is in the logfont parameter, which now includes a script field, shown in bold below:

typedef struct tagENUMLOGFONTEX {
LOGFONT elfLogFont;
BYTE elfFullName[LF_FULLFACESIZE];
BYTE elfStyle[LF_FACESIZE];
BYTE elfScript[LF_FACESIZE];
} ENUMLOGFONTEX, FAR *LPENUMLOGFONTEX;