Foxtable(狐表)用户栏目专家坐堂 → 字体安装


  共有2250人关注过本帖树形打印复制链接

主题:字体安装

帅哥哟,离线,有人找我吗?
有点色
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:13837 积分:69650 威望:0 精华:0 注册:2016/11/1 14:42:00
  发帖心情 Post By:2017/6/13 18:40:00 [显示全部帖子]

下面的代码,win7测试无效,xp好像可以

 

全局代码

 

<DllImport("gdi32.dll")> _
Public Function AddFontResource(ByVal lpFileName As String) As Integer
End Function
<DllImport("gdi32.dll")> _
Public Function RemoveFontResource(ByVal lpFileName As String) As Integer
End Function
<DllImport("kernel32.dll")> _
Public Function WriteProfileString(ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Integer
End Function
<DllImport("user32.dll")> _
Public Function SendMessage(ByVal hWnd As Integer, ByVal Msg As UInteger, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
End Function


Public Function installFont(ByVal orginFontPath As String, FontFileName As String, FontName As String) As Integer
Dim WinFontDir As String = String.Format("{0}\fonts\", System.Environment.GetEnvironmentVariable("WINDIR"))
Dim Ret As Integer = 0
Dim Res As Integer
Dim FontPath As String
Const WM_FONTCHANGE As Integer = 29
Const HWND_BROADCAST As Integer = 65535
FontPath = WinFontDir + FontFileName

Try
    If io.File.Exists(FontPath) Then
        removeFont(FontPath)      
    End If
   
    If Not io.File.Exists(FontPath) Then
        io.File.Copy(orginFontPath + FontFileName, FontPath)
        Ret = AddFontResource(FontPath)
       
        'Res = SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0)
       
        WriteProfileString("fonts", (FontName + "(TrueType)"), FontFileName)
    End If
Catch e As Exception
    msgbox(e.message)
End Try
Return Ret
End Function

Public Function removeFont(ByVal FontFilePathName As String) As Integer
Try
    RemoveFontResource(FontFilePathName)
    io.File.Delete(FontFilePathName)
Catch e As Exception
    msgbox(e.message)
    Return 0
End Try

Return 1
End Function

 

调用代码

 

InstallFont("g:\", "SIMYOU.TTF", "SIMYOU")


 回到顶部