安装字体
2014-04-04 11:22
363 查看
字体的安装需要调用到系统的api
[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,uint msg,int wParam, int lParam); [DllImport("gdi32")] public static extern int AddFontResource(string lpFileName);
public static bool installFont(FileInfo fontFileInfo) { try { Console.Write("installing font {0}", fontFileInfo.Name); string fontFileName = fontFileInfo.Name; string fontName = fontFileInfo.Name.Substring(0, fontFileInfo.Name.LastIndexOf(".", StringComparison.Ordinal)); //获取字体名称 const int wmFontchange = 0x001D; const int hwndBroadcast = 0xffff; string fontPath = string.Format(@"{0}\fonts\{1}",Environment.GetEnvironmentVariable("windir"),fontFileName ) ; if (!File.Exists(fontPath)) { File.Copy(fontFileInfo.FullName, fontPath); //将字体文件拷贝至系统目录 AddFontResource(fontPath); //************************ SendMessage(hwndBroadcast, wmFontchange, 0, 0);//************************ WriteProfileString("fonts", fontName + "(TrueType)", fontFileName);//************************ return true; } } catch (Exception exception) { Console.WriteLine("Error {0}",exception.Message); } return true; }
相关文章推荐
- 0011_奇偶数分离
- weblogicc 线程池设置
- 多用途WP主题商务特点应用介绍
- 存储过程备份数据库
- Oracle分页查询
- 一个不错的错误提醒宏
- redis内存相关配置conf
- Eclipse Java EE + Tomcat 搭建J2EE开发环境
- python模块subprocess学习
- htop 内存使用率计算
- html5移动开发有什么优势
- TCP/IP详解--影响TCP性能的几种协议因素
- strcpy函数的实现
- apache2.2 安装php5
- unity博文搜集
- 一个不错的错误提醒宏
- RS-232-C串口通讯协议解析
- 关于设置shadowPath
- [易语言]连接MSSQLSERVER数据库学习
- 在树莓派上一键安装Django