添加系统字体mfc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | void CFontConfigDlg::OnBnClickedBtnInstall() { //安装字体 CString strFullPath = _T(“”); CString strFileName = _T(“”); CString strFontName = _T(“”); if (!GetTtfFontFile(strFullPath, strFileName, strFontName)) { return ; } CString strSysPath = GetSysFontPath(); CString strSysFile = strSysPath + strFileName; if (PathFileExists(strSysFile)) { MessageBox(_T(“系统字体已存在!”), _T(“提示”), MB_OK|MB_ICONWARNING); return ; } if (!CopyFile(strFullPath, strSysFile, FALSE)) { MessageBox(_T(“复制字体文件失败!”), _T(“提示”), MB_OK|MB_ICONERROR); return ; } //添加字体到系统字体表 int nFontNum = AddFontResource(strSysFile); if (nFontNum <= 0) { MessageBox(_T(“AddFontResource失败!”), _T(“提示”), MB_OK|MB_ICONERROR); return ; } //永久字体注册 HKEY phkResult; DWORD RegResult; LONG Rlt = RegCreateKeyEx(HKEY_LOCAL_MACHINE,_T(“SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts”), 0, _T(“REG_SZ”), 0, KEY_WRITE, 0, &phkResult, &RegResult); if (Rlt != ERROR_SUCCESS) { MessageBox(_T(“注册表键值创建失败!”), _T(“提示”), MB_OK|MB_ICONERROR); return ; } //CString转BYTE* int nLength = strFileName.GetLength(); string sFileName = strFileName.GetBuffer(nLength); BYTE * m_byte=( BYTE *)sFileName.c_str(); Rlt = RegSetValueEx(phkResult, strFontName, 0, REG_SZ, m_byte, nLength); if (Rlt != ERROR_SUCCESS) { MessageBox(_T(“注册表键值设置失败!”), _T(“提示”), MB_OK|MB_ICONERROR); return ; } Rlt = RegCloseKey(phkResult); if (Rlt != ERROR_SUCCESS) { MessageBox(_T(“注册表键值关闭失败!”), _T(“提示”), MB_OK|MB_ICONERROR); return ; } ::SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0); MessageBox(_T(“注册字体成功!”), _T(“提示”), MB_OK|MB_ICONINFORMATION); } void CFontConfigDlg::OnBnClickedBtnUnins() { //卸载字体 CString strFullPath = _T(“”); CString strFileName = _T(“”); CString strFontName = _T(“”); if (!GetTtfFontFile(strFullPath, strFileName, strFontName)) { return ; } CString strSysPath = GetSysFontPath(); CString strSysFile = strSysPath + strFileName; if (!PathFileExists(strSysFile)) { MessageBox(_T(“系统字体文件不存在!”), _T(“提示”), MB_OK|MB_ICONWARNING); return ; } //删除注册表 HKEY registryKey; LONG Rlt = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T(“SOFTWARE\\Microsoft\ |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2019-03-13 PBYTE
2018-03-13 setitemdata 32位 or 64位