How can I install a new font in VB6 code?

5 pts.
Tags:
Fonts
VB 6
Visual Basic
Visual Basic 6
How i can install new font in vb6 code?

Answer Wiki

Thanks. We'll let you know when a new response is added.

Yes there is a way. You use the AddFontResource function. It was made expressly for that purpose. It has been around since Win 3.1.

The AddFontResource function adds the font resource from the specified file to the system font table. The font can subsequently be used for text output by any application.

To mark a font as private or no enumerable, use the AddFontResourceEx function.

Here is an example: AddFrontResource

Private Const HWND_BROADCAST = &HFFFF&
Private Const WM_FONTCHANGE = &H1D
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 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

int AddFontResource(
LPCTSTR lpszFilename // font file name
);

Parameters

lpszFilename
[in] Pointer to a null-terminated character string that contains a valid font file name. This parameter can specify any of the following files.
File extension Description
.fon Font resource file.
.fnt Raw bitmap font file.
.ttf Raw TrueType file.
.ttc East Asian Windows: TrueType font collection.
.fot TrueType resource file.
.otf PostScript OpenType font.
.mmm multiple master Type1 font resource file. It must be used with .pfm and .pfb files.
.pfb Type 1 font bits file. It is used with a .pfm file.
.pfm Type 1 font metrics file. It is used with a .pfb file.

Windows 2000/XP: To add a font whose information comes from several resource files, have lpszFileName point to a string with the file names separated by a | –for example, abcxxxxx.pfm | abcxxxxx.pfb.

Return Values

If the function succeeds, the return value specifies the number of fonts added.

If the function fails, the return value is zero. No extended error information is available.
Remarks

Any application that adds or removes fonts from the system font table should notify other windows of the change by sending a WM_FONTCHANGE message to all top-level windows in the operating system. The application should send this message by calling the SendMessage function and setting the hwnd parameter to HWND_BROADCAST.

When an application no longer needs a font resource that it loaded by calling the AddFontResource function, it must remove that resource by calling the RemoveFontResource function.

This function installs the font only for the current session. When the system restarts, the font will not be present. To have the font installed even after restarting the system, the font must be listed in the registry.

Windows 95/98/Me: AddFontResourceW is supported by the Microsoft Layer for Unicode. To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.

**************************************
You can also check here for managing fonts according to Microsoft.
Good Luck!
-Flame

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Yoooooooooo
      1. 
        src="http://" alt="" />[B
    ]kdsks
20 pointsBadges:
report
  • Yoooooooooo
    carita
    20 pointsBadges:
    report
  • Forgot Password

    No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

    Your password has been sent to:

    To follow this tag...

    There was an error processing your information. Please try again later.

    REGISTER or login:

    Forgot Password?
    By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

    Thanks! We'll email you when relevant content is added and updated.

    Following