'in a module (since the API requires a callback)
Option Explicit
Public Declare Function EnumFontFamiliesEx Lib "gdi32" Alias "EnumFontFamiliesExA" (ByVal hDC As Long, lpLogFont As LOGFONT, ByVal lpEnumFontProc As Long, ByVal lParam As Long, ByVal dwReserved As Long) As Long
Public Declare Function SendMessageString Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Public Const LB_ADDSTRING As Long = &H180
Public Const LF_FACESIZE As Long = 32
Public Const LF_FULLFACESIZE As Long = 64
Public Const ANSI_CHARSET As Long = 0
Public Type NEWTEXTMETRIC
tmHeight As Long
tmAscent As Long
tmDescent As Long
tmInternalLeading As Long
tmExternalLeading As Long
tmAveCharWidth As Long
tmMaxCharWidth As Long
tmWeight As Long
tmOverhang As Long
tmDigitizedAspectX As Long
tmDigitizedAspectY As Long
tmFirstChar As Byte
tmLastChar As Byte
tmDefaultChar As Byte
tmBreakChar As Byte
tmItalic As Byte
tmUnderlined As Byte
tmStruckOut As Byte
tmPitchAndFamily As Byte
tmCharSet As Byte
ntmFlags As Long
ntmSizeEM As Long
ntmCellHeight As Long
ntmAveWidth As Long
End Type
Public Type FONTSIGNATURE
fsUsb(4) As Long
fsCsb(2) As Long
End Type
Public Type NEWTEXTMETRICEX
ntmTm As NEWTEXTMETRIC
ntmFontSig As FONTSIGNATURE
End Type
Public Type LOGFONT
lfHeight As Long
lfWidth As Long
lfEscapement As Long
lfOrientation As Long
lfWeight As Long
lfItalic As Byte
lfUnderline As Byte
lfStrikeOut As Byte
lfCharSet As Byte
lfOutPrecision As Byte
lfClipPrecision As Byte
lfQuality As Byte
lfPitchAndFamily As Byte
lfFaceName(0 To (LF_FACESIZE - 1)) As Byte
End Type
Public Type ENUMLOGFONTEX
elfLogFont As LOGFONT
elfFullName(0 To (LF_FULLFACESIZE - 1)) As Byte
elfStyle(0 To (LF_FACESIZE - 1)) As Byte
elfScript(0 To (LF_FACESIZE - 1)) As Byte
End Type
Public Function EnumFontFamiliesExProc(ByRef lpelfe As ENUMLOGFONTEX, ByRef lpntme As NEWTEXTMETRICEX, ByVal FontType As Long, ByVal lParam As Long) As Long
Dim strFontName As String
'convert the font name into a unicode string
strFontName = StrConv(lpelfe.elfLogFont.lfFaceName, vbUnicode)
'trim off the null terminator
strFontName = Left$(strFontName, InStr(strFontName, vbNullChar) - 1)
'add the name to the listbox (lParam is the hWnd passed in)
SendMessageString lParam, LB_ADDSTRING, 0, strFontName
'return 1 to continue enumeration
EnumFontFamiliesExProc = 1
End Function
'in a form with a listbox (or wherever you want to start filling the listbox
Private Sub Form_Load()
Dim lf As LOGFONT
'this will enumerate all fonts in the ANSI character set
lf.lfCharSet = ANSI_CHARSET
lf.lfFaceName(0) = 0
lf.lfPitchAndFamily = 0
'enumerate the fonts
EnumFontFamiliesEx Me.hDC, lf, AddressOf EnumFontFamiliesExProc, List1.hWnd, 0
End Sub