"Eduardo" <
m...@mm.com> wrote in message
news:kmj09c$7iu$1...@speranza.aioe.org...
> But even if that method (or writting the font in the registry) worked,
> I need a way to retrieve the font name(s) from the font file, and it
> seems that there is not a direct function to do that.
I've only just looked at your thread and I'm not really sure what problems
you are having installing fonts. I don't recall having any problems myself
when installing them with standard code using AddFontResourceEx, although I
usually install them for temporary use only by my own VB program using the
FR_PRIVATE flag. As for your problem with retrieving a face name from a font
file I think the CreateScalableFontResource function should help you with
that (see example code below).
Regarding the failure of the font to work as soon as it is installed, I
think I recall a little bug somewhere when using VB print methods in that in
order to get the font to be correctly selected first time as soon as it is
installed you need set any font attributes to something other than its
current setting /before/ you assign the newly installed font to you Form or
pictureBox or whatever and then set the attribute to what you really want
afterwards, for example:
Me.Font.Size = 1234
Me.Font.Name = "the newly installed font"
Me.Font.Size = 16
Anyway, here's some code which should get a font's face name from its ttf
file name:
Option Explicit
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 Function GetFontName(FileNameTTF As String) As String
Dim s1 As String, sFontName As String, sTempFile As String
Dim fn As Long, p1 As Long, retVal As Long
' create a path/name for a .FOT file (must NOT already exist)
' (the following line will do for now, but there are better ways)
sTempFile = App.Path & "\MikeTemp" & CStr(Int(Timer)) & ".FOT"
retVal = CreateScalableFontResource _
(1, sTempFile, FileNameTTF, vbNullString)
If retVal = 0 Then Exit Function ' the Call failed
' Call succeded and .FOT file created, so examine its contents
fn = FreeFile ' get the ext available VB file number
Open sTempFile For Binary Access Read As fn
s1 = Space(LOF(fn))
Get fn, 1, s1
p1 = InStr(s1, "FONTRES:") + 8
sFontName = Mid$(s1, p1, InStr(p1, s1, vbNullChar) - p1)
Close fn
Kill sTempFile ' kill the temporary .FOT file
GetFontName = sFontName
End Function
Private Sub Command1_Click()
Print GetFontName("c:\temp\somefont.ttf")
End Sub
Mike