home *** CD-ROM | disk | FTP | other *** search
/ Dan Appleman's Visual Bas…s Guide to the Win32 API / Dan.Applmans.Visual.Basic.5.0.Programmers.Guide.To.The.Win32.API.1997.Ziff-Davis.Press.CD / VB5PG32.mdf / vbpg32 / samples4 / ch11 / enmfntx.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-16  |  5.7 KB  |  170 lines

  1. VERSION 4.00
  2. Begin VB.Form enmfntx 
  3.    Caption         =   "Enum Font Example"
  4.    ClientHeight    =   3690
  5.    ClientLeft      =   1095
  6.    ClientTop       =   1500
  7.    ClientWidth     =   7215
  8.    BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
  9.       Name            =   "MS Sans Serif"
  10.       Size            =   8.25
  11.       Charset         =   0
  12.       Weight          =   700
  13.       Underline       =   0   'False
  14.       Italic          =   0   'False
  15.       Strikethrough   =   0   'False
  16.    EndProperty
  17.    ForeColor       =   &H80000008&
  18.    Height          =   4095
  19.    Left            =   1035
  20.    LinkTopic       =   "Form1"
  21.    ScaleHeight     =   3690
  22.    ScaleWidth      =   7215
  23.    Top             =   1155
  24.    Width           =   7335
  25.    Begin VB.ListBox List2 
  26.       Height          =   1395
  27.       Left            =   60
  28.       TabIndex        =   4
  29.       Top             =   600
  30.       Width           =   6975
  31.    End
  32.    Begin VB.CommandButton cmdListTrueType 
  33.       Appearance      =   0  'Flat
  34.       BackColor       =   &H80000005&
  35.       Caption         =   "List All TrueType"
  36.       Height          =   435
  37.       Left            =   1560
  38.       TabIndex        =   3
  39.       Top             =   120
  40.       Width           =   1755
  41.    End
  42.    Begin VB.CommandButton CmdListVariations 
  43.       Appearance      =   0  'Flat
  44.       BackColor       =   &H80000005&
  45.       Caption         =   "List Variations"
  46.       Height          =   435
  47.       Left            =   5280
  48.       TabIndex        =   2
  49.       Top             =   120
  50.       Width           =   1755
  51.    End
  52.    Begin VB.CommandButton CmdListFonts 
  53.       Appearance      =   0  'Flat
  54.       BackColor       =   &H80000005&
  55.       Caption         =   "List All Fonts"
  56.       Height          =   435
  57.       Left            =   3420
  58.       TabIndex        =   1
  59.       Top             =   120
  60.       Width           =   1755
  61.    End
  62.    Begin VB.ListBox List1 
  63.       Height          =   1200
  64.       Left            =   60
  65.       TabIndex        =   0
  66.       Top             =   2280
  67.       Width           =   6975
  68.    End
  69.    Begin VB.Label Label2 
  70.       BackStyle       =   0  'Transparent
  71.       Caption         =   "Font variations with a family:"
  72.       Height          =   255
  73.       Left            =   60
  74.       TabIndex        =   6
  75.       Top             =   2040
  76.       Width           =   2595
  77.    End
  78.    Begin VB.Label Label1 
  79.       BackStyle       =   0  'Transparent
  80.       Caption         =   "Font families:"
  81.       Height          =   255
  82.       Left            =   60
  83.       TabIndex        =   5
  84.       Top             =   300
  85.       Width           =   1395
  86.    End
  87.    Begin Cbkd.Callback Callback1 
  88.       Left            =   6540
  89.       Top             =   1740
  90.       _Version        =   262144
  91.       _ExtentX        =   847
  92.       _ExtentY        =   847
  93.       _StockProps     =   0
  94.       Type            =   2
  95.    End
  96. Attribute VB_Name = "enmfntx"
  97. Attribute VB_Creatable = False
  98. Attribute VB_Exposed = False
  99. Option Explicit
  100. ' Copyright 
  101.  1997 by Desaware Inc. All Rights Reserved.
  102. Private Sub Callback1_EnumFonts(lpLogFont As Long, lpTextMetrics As Long, nFontType As Long, lpData As Long, retval As Long)
  103.     Dim fullname$, stylename$, facename$
  104.     ' agCopyData copies the data referenced by the pointer
  105.     ' provided into a structure
  106.     agCopyData ByVal lpLogFont, nlf, Len(nlf)
  107.     agCopyData ByVal lpTextMetrics, ntm, Len(ntm)
  108.     ' Only look at TrueType fonts.
  109.     If (lpData = 1) And ((nFontType And TRUETYPE_FONTTYPE) = 0) Then Exit Sub
  110.     If (nFontType And TRUETYPE_FONTTYPE) <> 0 Then
  111.         fullname$ = GetNameFromByteArray(nlf.elfFullName)
  112.         stylename$ = GetNameFromByteArray(nlf.elfStyle)
  113.     End If
  114.     If lpData = 2 And (nFontType And RASTER_FONTTYPE) <> 0 Then
  115.         fullname$ = " Height,Width: " & ntm.tmHeight & "," & ntm.tmAveCharWidth
  116.     End If
  117.     ' Non truetype fonts do not have a valid lfFullname and lfStyle field
  118.     facename$ = GetNameFromByteArray(nlf.elfLogFont.lfFaceName)
  119.     If lpData = 2 Then
  120.         list1.AddItem facename$ & " -- " & fullname$ & " " & stylename$
  121.     Else
  122.         List2.AddItem facename$ & " -- " & fullname$ & " " & stylename$
  123.     End If
  124. End Sub
  125. Private Sub CmdListVariations_Click()
  126.     Dim di&
  127.     Dim fname$
  128.     Dim f%
  129.     list1.Clear
  130.     fname$ = List2.Text
  131.     f% = InStr(fname$, " -- ")
  132.     If f% > 0 Then
  133.         fname$ = Left$(fname$, f% - 1)
  134.     End If
  135.     ' This gets Arial only (all styles)
  136.     di = EnumFontFamilies(hdc, fname$, callback1.ProcAddress, 2)
  137. End Sub
  138. Private Sub CmdListFonts_Click()
  139.     Dim di&
  140.     list1.Clear
  141.     List2.Clear
  142.     ' This gets one font for each family
  143.     di = EnumFontFamilies(hdc, vbNullString, callback1.ProcAddress, 0)
  144. End Sub
  145. Private Sub cmdListTrueType_Click()
  146.     Dim di&
  147.     list1.Clear
  148.     List2.Clear
  149.     ' This gets one font for each family
  150.     ' Danger - be sure to use vbNullString, not 0!  Nasty VB type conversion!
  151.     di = EnumFontFamilies(hdc, vbNullString, callback1.ProcAddress, 1)
  152. End Sub
  153. ' Retrieves a string from a byte array which contains
  154. ' a null terminated ANSI string
  155. Public Function GetNameFromByteArray$(src() As Byte)
  156.     Dim t$, zeropos%
  157.     ' The array is ANSI, and needs to be converted into Unicode
  158.     ' to fit VB's internal format
  159.     t$ = StrConv(CStr(src), vbUnicode)
  160.     ' And remove the null terminating character and any trailing characters
  161.     zeropos% = InStr(t$, Chr$(0))
  162.     If zeropos% > 1 Then t$ = Left$(t$, zeropos% - 1)
  163.     GetNameFromByteArray$ = t$
  164. End Function
  165. Private Sub Form_Load()
  166. End Sub
  167. Private Sub List2_Click()
  168.     CmdListVariations_Click
  169. End Sub
  170.