求真百科歡迎當事人提供第一手真實資料,洗刷冤屈,終結網路霸凌。

AddFontResource

事實揭露 揭密真相
前往: 導覽搜尋

AddFontResourceVB中的示例

Private Declare Function AddFontResource Lib "gdi32" Alias "AddFontResourceA" (ByVal lpFileName As String) As Long

Private Declare FunctionRemoveFontResourceLib "gdi32" Alias "RemoveFontResourceA" (ByVal lpFileName As String) As Long

Dim AppPath As String

Private Sub Form_Load()

'The KPD-Team 2001

AppPath =App.Path

If Right$(AppPath, 1) <> "\" Then AppPath = AppPath + "\"

'Add the font to the Windows Font Table

AddFontResource AppPath + "myfont.ttf"

'Write something on the form

Me.AutoRedraw = True

Me.FontName = "myfont"

Me.Print "This is a test!"

End Sub

Private Sub Form_Unload(Cancel As Integer)

'Remove the font from the Windows Font Table

RemoveFontResource AppPath + "myfont.ttf"

End Sub[1]

[]

基本內容

函數功能:該函數從指定的文件里增加字體資源到系統字體表,這些字體可隨後被任何基於Win32的應用程序用來作正文輸出。

函數原型:int AddFontResource(LPCTSTR lpszFilename);

參數:

lpszFilename:指向含有一個有效的字體文件的文件名,它是以\0結束的字符串的指針,此文件名可以指定一個.FON字體資源文件、一個.FNT未加工位圖字體文件、一個.TTF未加工TrueType文件或一個.FON TrueType資源文件。

返回值:如果函數調用成功,則返回值為增加的字體數;如果函數調用失敗,返回值是0。

Windows NT:若想獲得更多錯誤信息,請調用GetLastError函數。

備註:任何增加或刪除系統字體表中字體的應用程序都必須以發WM_FONTCHANGE消息給操作系統中所有最頂層的窗口來通過其他窗口字體的改變,應用程序調用SendMessage和設置參數hwnd為HWND_BROADCAST來發送消息。

當一個應用程序不再需要一種由調用AddFontResource加載進來的字體資源,應該用RemoveFontResource來刪除這種資源。

Windows CE:版本1.0僅支持光柵字體。Windows CE 2.0版本支持使用TrueType字體或光柵字體其中之一的系統,字體類型(光柵或TrueType)在系統設計時就已確定,不能被一個應用程序修改。

速查:Windows NT:3.1及以上版本;Windows:95及以上版本;Windows CE:1.0及以上版本;頭文件:wingdi.h;庫文件:gdi32.lib;Unicode:在Windows NT環境下以Unicode和ANSI兩種方式實現。

參考文獻