DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Install fonts

  1. #1
    Sanjay Guest

    Install fonts

    Hi guys
    Any body knows how to install fonts in vb
    is there any api or something

  2. #2
    Tim Manos Guest

    Re: Install fonts


    You just copy the font file you want to install to the \Windows\fonts
    folder. Is that what you're asking?


    Sanjay <3b04ef84$1@news.devx.com>...
    >Hi guys
    >Any body knows how to install fonts in vb
    >is there any api or something

  3. #3
    Karl E. Peterson Guest

    Re: Install fonts

    Hi Sanjay --

    > Any body knows how to install fonts in vb
    > is there any api or something

    Here's some old code I stumbled across this morning, while looking for something

    Option Explicit

    Private Const HWND_BROADCAST = &HFFFF&
    Private Const WM_FONTCHANGE = &H1D

    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

    Private Declare Function AddFontResource Lib "gdi32" Alias "AddFontResourceA" (ByVal
    lpFileName As String) As Long

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As
    Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

    Public Sub InstallFont(ByVal sTTFFile As String)
    Dim iExt As Integer
    Dim iBackslash As Integer
    Dim sDestPath As String
    Dim sFileName As String
    Dim sFOTFile As String
    Dim sSrcPath As String

    ' Find last backslash in TTF file name
    iBackslash = InStrRev(sTTFFile, "\")
    If iBackslash Then
    ' Exract path and file name
    sSrcPath = Left$(sTTFFile, iBackslash)
    sFileName = Mid$(sTTFFile, iBackslash + 1)
    ' If no backslash, assume file is
    ' in current directory
    sSrcPath = CurDir$
    sFileName = sTTFFile
    End If

    ' Find .TTF file extension
    iExt = InStr(sFileName, ".ttf")
    ' Generate .FOT file name
    If iExt Then
    sFOTFile = Left$(sFileName, iExt - 1) & ".fot"
    sFOTFile = sFileName & ".fot"
    End If

    ' Optional: Copy TTF file to font folder
    sDestPath = GetFontFolder()
    FileCopy sTTFFile, sDestPath & sFileName

    ' Call CreateScalableFontResource
    ' to create .FOT file
    Call CreateScalableFontResource(0, sFOTFile, sFileName, sDestPath)

    ' Call AddFontResource to install font
    Call AddFontResource(sFOTFile)

    ' Call SendMessage to notify other apps
    ' that font has been added
    Call SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0)

    ' Delete font resource file
    Kill sDestPath & sFOTFile
    End Sub

    Most of this work is only necessary if you want other applications to know
    immediately that the font is available.

    Later... Karl

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.