-
Install fonts
Hi guys
Any body knows how to install fonts in vb
is there any api or something
-
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
>
>
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks