Results 1 to 4 of 4

Thread: How do I install fonts automatically?

  1. #1

    Thread Starter
    Member FinnPanther's Avatar
    Join Date
    Jun 2001
    Location
    Finland
    Posts
    53

    Question How do I install fonts automatically?

    In this moment I'm simply extracting the required font files to the Windows\FONTS -folder, and then my program opens the FONTS -folder for the user to see if the fonts are there.

    Is there a way to install the fonts so that they work right away and absolutely 100% sure? Is it possible to run the "Install new font" -program with the chosen font automatically?

    The method I'm using now usually works, but sometimes it doesn't. The font types are TrueType and "normal", and the number of fonts is 4 (unless my memory has been erased ).
    -Panther

    Panther's HQ

  2. #2
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    Use the AddFontResource API call, all you have to do is simply pass it the filename of the font you want to add, the return value is the number of fonts added to the system (or 0 if an error occurred), you also need to alert all the top level windows that you have a added a font using SendMessage and the WM_FONTCHANGE message....

    Code:
    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
    Private Const HWND_BROADCAST = &HFFFF&
    Private Const WM_FONTCHANGE = &H1D
    
    Private Sub Form_Load()
     Dim res As Long
     
        ' add the font
        res = AddFontResource("C:\Fonts\Nordic__.ttf")
        
        If res > 0 Then
            
            ' alert all windows that a font was added
            SendMessage HWND_BROADCAST, WM_FONTCHANGE, 0, 0
            
            MsgBox res & " fonts were added!"
        
        End If
    End Sub
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  3. #3

    Thread Starter
    Member FinnPanther's Avatar
    Join Date
    Jun 2001
    Location
    Finland
    Posts
    53

    Question Uh...

    Err... Thanks, but it didn't work like it was supposed to

    It feeds the font to the system (you can't delete the font anymore unless you reboot) and the return value is > 0.

    The sendmessage works also, because all of the visible windows "flash" (or reload) quickly.

    But, the problem still exists. I tried loading the fonts/messaging windows in every form's load procedure, but it didn't work

    I also tried copying the font to the fonts folder first and then adding...

    OH MY GOD WHAT A DUMPASS I HAVE BEEN!

    Now I got it! (Or at least I think so ) You'll have to use the API to the font in the fonts folder! (?) If it works that way, thanks.

    I always forget something...
    -Panther

    Panther's HQ

  4. #4
    Frenzied Member MrGTI's Avatar
    Join Date
    Oct 2000
    Location
    Ontario, Canada
    Posts
    1,277

    Talking

    I just use my Wise installer to install the program and any related fonts. Works much easier.
    ~Peter


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width