黄聪:使用c#代码安装系统字体
2010-03-26 04:12
489 查看
[DllImport("kernel32.dll", SetLastError = true)]
static extern int WriteProfileString(string lpszSection, string lpszKeyName, string lpszString);
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, // handle to destination window
uint Msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);
[DllImport("gdi32")]
public static extern int AddFontResource(string lpFileName);
private void installFont()
{
string WinFontDir = "C:\\windows\\fonts";
string FontFileName = "DS-Digital Bold Italic.TTF";
string FontName = "DS-Digital Bold Italic";
int Ret;
int Res;
string FontPath;
const int WM_FONTCHANGE = 0x001D;
const int HWND_BROADCAST = 0xffff;
FontPath = WinFontDir + "\\" + FontFileName;
if (!File.Exists(FontPath))
{
File.Copy(System.Windows.Forms.Application.StartupPath + "\\DS-Digital Bold Italic.TTF", FontPath);
Ret = AddFontResource(FontPath);
Res = SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
Ret = WriteProfileString("fonts", FontName + "(TrueType)", FontFileName);
}
}
static extern int WriteProfileString(string lpszSection, string lpszKeyName, string lpszString);
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, // handle to destination window
uint Msg, // message
int wParam, // first message parameter
int lParam // second message parameter
);
[DllImport("gdi32")]
public static extern int AddFontResource(string lpFileName);
private void installFont()
{
string WinFontDir = "C:\\windows\\fonts";
string FontFileName = "DS-Digital Bold Italic.TTF";
string FontName = "DS-Digital Bold Italic";
int Ret;
int Res;
string FontPath;
const int WM_FONTCHANGE = 0x001D;
const int HWND_BROADCAST = 0xffff;
FontPath = WinFontDir + "\\" + FontFileName;
if (!File.Exists(FontPath))
{
File.Copy(System.Windows.Forms.Application.StartupPath + "\\DS-Digital Bold Italic.TTF", FontPath);
Ret = AddFontResource(FontPath);
Res = SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
Ret = WriteProfileString("fonts", FontName + "(TrueType)", FontFileName);
}
}
相关文章推荐
- 使用C#代码安装 Windows 服务(不使用InstallUtil) (转帖)
- C#使用Mutex实现系统范围内单实例运行的示例代码
- C# DllImport 系统调用使用详解 托管代码的介绍 EntryPoint的使用
- C#遍历系统所安装的打印机,使用WMI方式获取打印机的所有属性
- 嵌入资源的方式让Winform使用系统没有的字体,无需安装字体
- C# DllImport 系统调用使用详解、托管代码的介绍、EntryPoint的使用
- 使用C#代码安装 Windows 服务(不使用InstallUtil)
- C#遍历系统所安装的打印机,使用WMI方式获取打印机的所有属性
- 黄聪:C#代码生成工具:文本模板初体验 使用T4批量修改实体框架(转载)
- 实测如何使用c#代码判断服务器是否安装iis
- 转:使用C#代码安装 Windows 服务(不使用InstallUtil)
- 使用C#代码安装、启动、停止、卸载Windows service(不使用InstallUtil.exe)
- C#中怎么使用系统默认浏览器打开指定的URL(代码实现)
- 使用C#调用系统API实现内存注入的代码
- C#中获取当前系统中安装的所有字体及预定义颜色
- 使用C#代码安装 Windows 服务(不使用InstallUtil)
- 使用C#代码设置系统日期和时间
- 【转帖】C# DllImport 系统调用使用详解 托管代码的介绍 EntryPoint的使用
- 黄聪:C#获取系统中的所有字体
- 使用批处理或C#代码 注册ArcEngine Runtime授权,自动检测AE Runtime安装位置