AddFontResource

AddFontResource是指定的檔案里增加字型資源到系統字型表。

基本介紹

  • 中文名:AddFontResource
  • 原型:int AddFontResource
  • 參數:lpszFilename
函式功能:該函式從指定的檔案里增加字型資源到系統字型表,這些字型可隨後被任何基於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兩種方式實現。
VB中的示例
Private Declare Function AddFontResource Lib "gdi32" Alias "AddFontResourceA" (ByVal lpFileName As String) As Long
Private Declare Function RemoveFontResource Lib "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

相關詞條

熱門詞條

聯絡我們