Results 1 to 3 of 3

Thread: Display Fonts that aren't installed

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Posts
    2

    Post

    Hi there,

    does anybody have an idea how to display fonts that aren't installed in my system?

  2. #2
    Addicted Member
    Join Date
    Jan 1999
    Posts
    239

    Post

    If their not installed how are you going to
    see/display them?

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2000
    Posts
    2

    Post

    Originally posted by johnpc:
    If their not installed how are you going to
    see/display them?
    I found the solution. I call the WinAPI AddFontResource and I am able to use fonts that aren't in the Windows Font directory like shown below (I typed it in quickly so maybe I mistyped something):

    Private Declare Function AddFontResource Lib "gdi32" Alias "AddFontResourceA" (ByVal lpFileName As String) As Long
    Private Declare Function RemoveFontResource Lib "gdi32" Alias "RemoveFontResourceA" (ByVal lpFileName As String) As Long
    Private Declare Function CreateScalableFontResource Lib "gdi32" Alias "CreateScalableFontResourceA" (ByVal fHidden As Long, ByVal lpszResourceFile As String, ByVal lpszFontFile As String, ByVal lpszCurrentPath As String) As Long

    Sub SomeCommand()
    Dim sz As String
    sz = "C:\Windows\Desktop\MyFont.ttf"
    AddFontResource(sz)
    Text1.Font = GetFontName(sz)
    RemoveFontResource(sz)
    End Sub

    Public Function GetFontName(FileNameTTF As String) As String
    Dim hFile As Integer
    Dim Buffer As String
    Dim FontName As String
    Dim TempName As String
    Dim iPos As Integer

    'Build name for new resource file in
    'a temporary file, and call the API.
    TempName = App.Path & "\~TEMP.FOT"

    If CreateScalableFontResource(1, _
    TempName, _
    FileNameTTF, _
    vbNullString) Then
    'The name sits behind the text "FONTRES:"
    hFile = FreeFile

    Open TempName For Binary Access Read As hFile
    Buffer = Space(LOF(hFile))
    Get hFile, , Buffer
    iPos = InStr(Buffer, "FONTRES:") + 8
    FontName = Mid(Buffer, iPos, _
    InStr(iPos, Buffer, vbNullChar) - iPos)
    Close hFile

    Kill TempName
    End If

    GetFontName = FontName
    End Function


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width