Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleLearn about the system font
DescriptionThis example shows how to learn about the system font in Visual Basic 6. It uses the GetStockObject API function to load the SYSTEM_FONT. Then it uses GetTextFace and GetTextMetrics to get information about the font.
Keywordssystem font, font
CategoriesGraphics, Windows
 
The program uses the GetStockObject API function with the SYSTEM_FONT parameter to load the system font. It installs the font by calling SelectObject. It then uses the GetTextFace and GetTextMetrics API functions to get information about the font.
 
Private Sub Form_Load()
Dim new_font As Long
Dim old_font As Long
Dim txt As String
Dim text_metrics As TEXTMETRIC
Dim face_name As String
Dim face_len As Long

    ' Load the system font into the form.
    new_font = GetStockObject(SYSTEM_FONT)
    old_font = SelectObject(hdc, new_font)

    ' Get the font's name.
    face_name = Space$(256)
    face_len = GetTextFace(hdc, Len(face_name), face_name)
    face_name = Left$(face_name, face_len)
    lblFaceName.Caption = face_name

    ' Get the font's metrics.
    GetTextMetrics hdc, text_metrics

    txt = ""
    If text_metrics.tmWeight >= 700 Then txt = txt & "bold "
    If text_metrics.tmItalic Then txt = txt & "italic "
    If text_metrics.tmUnderlined Then txt = txt & _
        "underlined "
    If text_metrics.tmStruckOut Then txt = txt & _
        "strikethrough "
    lblFontDescr.Caption = txt

    ' Display a sample in this font.
    CurrentX = 60
    CurrentY = lblFontDescr.Top + lblFontDescr.Height + 120
    Print "This text was drawn in the system font"

    ' Reselect the form's original font.
    SelectObject hdc, old_font

    ' Display a sample in the original font.
    CurrentX = 60
    Print "This text was drawn in the form's original font"
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated