EnumFonts

2.x

  int EnumFonts(hdc, lpszFace, fntenmprc, lParam)    
  HDC hdc; /* handle of device context */
  LPCSTR lpszFace; /* address of font name */
  FONTENUMPROC fntenmprc; /* address of callback function */
  LPARAM lParam; /* application-defined data */

The EnumFonts function enumerates the fonts available for a given device. This function is provided for backwards compatibility with earlier versions of Windows; current applications should use the EnumFontFamilies function.

EnumFonts continues until there are no more fonts or the callback function returns zero.

Parameters

hdc

Identifies the device context.

lpszFace

Points to a null-terminated string that specifies the names of the requested fonts. If this parameter is NULL, the EnumFonts function randomly selects and enumerates one font from each available typeface.

fntenmprc

Specifies the procedure-instance address of the application-defined callback function. The address must be created by the MakeProcInstance function. For more information about the callback function, see the description of the EnumFontsProc callback function.

lParam

Specifies a 32-bit application-defined value that is passed to the callback function along with the font information.

Return Value

The return value specifies the last value returned by the callback function and is defined by the user.

Comments

The EnumFonts function retrieves information about the specified font and passes it to the function pointed to by the fntenmprc parameter. The application-supplied callback function can process the font information, as necessary.

If the device is capable of text transformations (scaling, italicizing, and so on), only the base font will be enumerated. The user must know the device's text-transformation abilities to determine which additional fonts are available directly from the device. The graphics device interface (GDI) can simulate the bold, italic, underlined, and strikeout attributes for any GDI-based font.

The EnumFonts function enumerates fonts from the GDI internal table only. This does not include fonts that are generated by a device, such as fonts that are transformations of fonts from the internal table. The GetDeviceCaps function can be used to determine which transformations a device can perform. This information is available by using the TEXTCAPS index.

GDI can scale GDI-based raster fonts by one to five units horizontally and one to eight units vertically, unless PROOF_QUALITY is being used.

Example

The following example uses the MakeProcInstance function to create a pointer to the callback function for the EnumFonts function. The FreeProcInstance function is called when enumeration is complete. Because the second parameter is “Arial”, EnumFonts enumerates the Arial fonts available in the given device context. The cArial variable is passed to the callback function.

FONTENUMPROC lpEnumFontsCallBack;
int cArial = 0;

lpEnumFontsCallBack = (FONTENUMPROC) MakeProcInstance(
    (FARPROC) EnumFontsCallBack, hAppInstance);
EnumFonts(hdc, "Arial", lpEnumFontsCallBack, (LPARAM) &cArial);
FreeProcInstance((FARPROC) lpEnumFontsCallBack);

See Also

EnumFontFamilies, EnumFontsProc