How to install a font in WIN16/WIN32
Assumes
First copy the file to c:\windows\system (in Win 3.1 and Win NT) or to
c:\windows\fonts in Win 95 and call AddFont16 or AddFont32 from the
following code with the name of the font file; e.g. to install arial.ttf,
copy arial.ttf to \windows\system and then call AddFont16("arial.ttf")
API Declarations#If Win16 Then
Private Declare Function CreateScalableFontResource% Lib "GDI"
(ByVal fHidden%, ByVal lpszResourceFile$, ByVal lpszFontFile$, ByVal
lpszCurrentPath$)
Private Declare Function AddFontResource Lib "GDI" (ByVal
lpFilename As Any) As Integer
Private Declare Function WriteProfileString Lib "Kernel" (ByVal
lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As
String) As Integer
Private Declare Function SendMessage Lib "User" (ByVal hWnd As
Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As
Long
Declare Function GetSystemDirectory Lib "Kernel" (ByVal lpBuffer As
String, ByVal nSize As Integer) As Integer
Private Const HWND_BROADCAST As Integer = &HFFFF
Private Const WM_FONTCHANGE As Integer = &H1D
#End If
#If Win32 Then
'32-bit declares
Private Type OSVERSIONINFO
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
' Maintenance string for PSS usage
End Type
Private Declare Function PostMessage Lib "user32" _
Alias "PostMessageA" (ByVal hWnd As Long, ByVal _
wMsg As Long, ByVal wParam As Long, ByVal _
lParam As Long) As Long
Private Declare Function AddFontResource Lib "gdi32" _
Alias "AddFontResourceA" (ByVal lpFilename As _
String) As Long
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 RemoveFontResource Lib _
"gdi32" Alias "RemoveFontResourceA" (ByVal _
lpFilename As String) As Long
Private Declare Function GetWindowsDirectory Lib _
"kernel32" Alias "GetWindowsDirectoryA" (ByVal _
lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function GetSystemDirectory Lib _
"kernel32" Alias "GetWindowsDirectoryA" (ByVal _
lpBuffer As String, ByVal nSize As Long) As Long
Private Declare Function RegSetValueEx Lib _
"advapi32.dll" Alias "RegSetValueExA" (ByVal _
hKey As Long, ByVal lpValueName As String, _
ByVal Reserved As Long, ByVal dwType As Long, _
lpData As Any, ByVal cbData As Long) As Long
Private Declare Function RegOpenKey Lib _
"advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey _
As Long, ByVal lpSubKey As String, phkResult _
As Long) As Long
Private Declare Function RegCloseKey Lib _
"advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegDeleteValue Lib _
"advapi32.dll" Alias "RegDeleteValueA" (ByVal _
hKey As Long, ByVal lpValueName As String) As Long
Private Declare Function GetVersionEx Lib "kernel32" _
Alias "GetVersionExA" (lpVersionInformation As _
OSVERSIONINFO) As Long
' dwPlatformId defines:
Private Const VER_PLATFORM_WIN32_NT = 2
Private Const HWND_BROADCAST = &HFFFF&
Private Const WM_FONTCHANGE = &H1D
Private Const MAX_PATH = 260
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const REG_SZ = 1 ' Unicode null terminated string
#End If