Install fonts


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

    Hi,

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

    Tim

    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
    else:

    ===========================
    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)
    Else
    ' 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"
    Else
    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
    --
    http://www.mvps.org/vb



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
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

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