Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools


I tried so many places but never found any simple code which retrive font name. Because to set font for drawing/printing we have to set font name and ususally font name is different than file name.

Click here to copy the following block
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

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
 
 'Return the font name
  GetFontName = FontName
End Function

Private Sub Form_Load()
  Dim TTFontFile As String
 
 'get the font name for Arial Bold
 'be sure to verify that this font exists on your system
  TTFontFile = "c:\WINDOWS\Fonts\ANTQUAB.TTF"
  'MsgBox "Font name : " & GetFontName(TTFontFile)
  Me.caption = GetFontName(TTFontFile)
 
  Me.CurrentX = 1000
  Me.CurrentY = Me.Height / 2
  Me.FontName = GetFontName(TTFontFile)
  Me.FontSize = 15
  Me.FontBold = True
  Me.Print Me.caption & " Font Demo.."
End Sub


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.