Module: Fonts in Category Windows : Fonts from Total Visual SourceBook

Get the list of fonts installed on Windows, see if a font name is installed, and convert between points and height. Supports VB6 and VBA with 32 and 64-bit Windows API calls.

Procedure Name Type Description
(Declarations) Declarations Declarations and private variables for the modFonts module.
IsFontInstalled Procedure Determine if a font name is installed on the Windows Operating system.
GetFonts Procedure Enumerate the fonts installed on a system, returning the list of fonts in the array.
EnumFontFamProc Procedure This function should never be called directly by user code. It is used as a callback function for the Windows API EnumFontFamilies function. See the Windows SDK for more documentation on this procedure.
ConvertScale Procedure Converts between pixels, twips and points.
HeightToPoints Procedure Convert a font height to a font point size. The font height is measured in logical device units. Most windows API functions for dealing with fonts require the font height in logical units. This function only works correctly in the MM_TEXT mapping mode.
PointsToHeight Procedure Convert a font point size to a font height. The font height is measured in logical device units. Most windows API functions for dealing with fonts require the font height in logical units. This function only works correctly in the MM_TEXT mapping mode.
' Example of modFonts
'
' To use this example, create a new module and paste this code into it.
' Then run the procedure by putting the cursor in the procedure and pressing:
'    F5 to run it, or
'    F8 to step through it line-by-line (see the Debug menu for more options)

Private Sub Example_modFonts()
  ' Comments: Example of using the modFonts module to get the collection of fonts currently installed on Windows with VBA and VB6.
  '           See the results in the Immediate Window.

  Const clngHandle As Long = 0
  Dim astrFonts() As String
  Dim intFont As Integer

  ' Get all fonts on the system
  If GetFonts(clngHandle, astrFonts()) Then
    ' Fill the list box with the enumerated fonts
    For intFont = LBound(astrFonts) To UBound(astrFonts)
      Debug.Print intFont, astrFonts(intFont)
    Next intFont

    Debug.Print
    Debug.Print "Is Calibri font installed: " & IsFontInstalled("Calibri")
    Debug.Print "Is FMS font installed    : " & IsFontInstalled("FMS")
    Debug.Print
    Debug.Print "ConvertScale()"
    Debug.Print "16 pixels is " & ConvertScale(clngHandle, 16, cvscPixels, cvscpoints) & " points."
    Debug.Print "HeightToPoints(): 96 logical units is " & HeightToPoints(clngHandle, 96) & " points."
    Debug.Print "PointsToHeight(): 12 points is " & PointsToHeight(clngHandle, 12) & " logical units."

  Else
    MsgBox "Fonts could not be retrieved"
  End If

End Sub

Total Visual SourceBook The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.

Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!

Additional Resources

Total Visual SourceBook CD and Printed Manual

Microsoft Access/ Office 2016, 2013, 2010, and 2007 Version
is Shipping!

New features in Total Visual SourceBook for Access, Office and VB6

Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!


View all FMS products for Microsoft Access All Our Microsoft Access Products

Reviews

Reader Choice Award for MS Access Source Code Library
Reader Choice

"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."

Van T. Dinh, Microsoft MVP

SourceBook Info

Additional Info

Question

 

 

Free Product Catalog from FMS