Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > File I/O and Registry > Font installation


Reply
 
Thread Tools Display Modes
  #1  
Old 12-07-2004, 06:15 AM
iNcurSioN iNcurSioN is offline
Newcomer
 
Join Date: Dec 2004
Posts: 4
Default Font installation


Hi, I'm trying to install a font using VB, i basically want my program to use a custom font that does not come as standard with windows and therefore may not be on everyone's comuter.

Is there a simple way to add a new font into the windows font folder and then install it, the same way that windows does it if u go into the fonts folder and choose install font from the file menu?

Thanks for the help
Reply With Quote
  #2  
Old 12-07-2004, 06:28 AM
robertg's Avatar
robertg robertg is offline
Privileges Suspended
 
Join Date: Dec 2004
Location: Sterling Heights, MI
Posts: 520
Default

I got this routine from Karl Peterson's web site 3 or 4 years ago, and popped it into my Code Library. I've used it a couple of times, and it has worked for me. NOTE: Most of this work is only necessary if you want other applications to know
immediately that the font is available.

Code:
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
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->