Declare Function EnumFontFamilies Lib "gdi32.dll" Alias "EnumFontFamiliesA" (ByVal hdc As Long, ByVal lpszFamily As Any, ByVal lpEnumFontFamProc As Long, ByVal lParam As Long) As Long
EnumFontFamilies enumerates all of the fonts available for use on a device which use a certain typeface. The only trait that the function looks for in the enumerated fonts is that it uses the specified typeface. The enumerated fonts are individually passed to a callback function for processing.
The function returns whatever the final call to the callback function returned.
When passing 0 as lpszFamily, the expression CLng(0) must be used.
' This code is licensed according to the terms and conditions listed here.
' Enumerate some of the fonts available for window Form1.
' These fonts must have the Times New Roman typeface.
' Display some information about each font as it is enumerated.
' *** Place the following code in a module. ***
' The following callback function processes the enumerated fonts.
Public Function EnumFontFamProc (ByVal lpelf As Long, ByVal lpntm As Long, ByVal FontType As Long, ByVal lParam As Long) As Long
Dim elf As ENUMLOGFONT ' receives information about the font
Dim ntm As NEWTEXTMETRIC ' receives text metrics for TrueType fonts
Dim tm As TEXTMETRIC ' receives text metrics for non-TrueType fonts
' Copy the font information into the appropriate structure.
CopyMemory elf, ByVal lpelf, Len(elf)
' If the font is TrueType, use the following code.
If (FontType And TRUETYPE_FONTTYPE) = TRUETYPE_FONTTYPE Then
' Copy the text metrics into the appropriate structure.
CopyMemory ntm, ByVal lpntm, Len(ntm)
' Display the name of the font (removing empty space from it).
Debug.Print "Font Name: "; Left(elf.elfFullName, InStr(elf.elfFullName, vbNullChar) - 1);
Debug.Print " (TrueType font)"
' Display the style of the font (again removing empty space).
Debug.Print "Font Style: "; Left(elf.elfStyle, InStr(elf.elfStyle, vbNullChar) - 1)
' Display the average character width.
Debug.Print "Average Character Width:"; ntm.tmAveCharWidth
' Display the maximum character width.
Debug.Print "Maximum Character Width:"; ntm.tmMaxCharWidth
' If the font is not TrueType, use the following code.
Else
' Copy the text metrics into the appropriate structure.
CopyMemory tm, ByVal lpntm, Len(tm)
' Display the name of the font (removing empty space from it).
Debug.Print "Font Name: ";
Debug.Print Left(elf.elfLogFont.lfFaceName, InStr(elf.elfLogFont.lfFaceName, vbNullChar) - 1);
' Display whether the font is a device or a raster font.
If FontType = DEVICE_FONTTYPE Then
Debug.Print " (Device font)"
ElseIf FontType = RASTER_FONTTYPE Then
Debug.Print " (Raster font)"
End If
Debug.Print "Font Style does not apply for this font."
' Display the average character width.
Debug.Print "Average Character Width:"; tm.tmAveCharWidth
' Display the maximum character width.
Debug.Print "Maximum Character Width:"; tm.tmMaxCharWidth
End If
Debug.Print "***" ' separator
' Tell EnumFontFamilies to continue enumeration.
EnumFontFamProc = 1
End Function
' *** Place this code wherever you want the enumerate the fonts. ***
Dim retval As Long ' return value
' Enumerate all the fonts with the Times New Roman
' typeface which are available on Form1.
retval = EnumFontFamilies(Form1.hDC, "Times New Roman", AddressOf EnumFontFamProc, 0)
Debug.Print "Enumeration complete."
Go back to the alphabetical Function listing.
Go back to the Reference section index.
Last Modified: October 29, 1999
This page is copyright © 1999 Paul Kuliniewicz.
Copyright Information Revised October 29, 2000
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/e/enumfontfamilies.html