//安装emoji字体
void InsertEmojiFont()
{
CString sSourceDir =GetExePath()+_T("\\font\\");//exe路径
CString sFontFileName=_T("SEGUIEMJ.TTF");
//字体名称(将显示在字体对话框中).
CString sFontName=_T("Segoe UI Emoji (TrueType)");
TCHAR sWinDir[MAX_PATH];
GetWindowsDirectory(sWinDir,MAX_PATH);
CString sFontDir(sWinDir);
sFontDir += _T("\\Fonts\\");//C:\Windows\Fonts
BOOL bHadEmoji = TRUE;
HANDLE hFind;
WIN32_FIND_DATA wfd;
hFind=FindFirstFile(sFontDir + sFontFileName,&wfd);//C:\windows\Fonts\SEGUIEMJ.TTF
if(hFind==INVALID_HANDLE_VALUE)
bHadEmoji = FALSE;//不存在
FindClose(hFind);
if (bHadEmoji)
{
//*** 本地已存在 emoji 字体 ***
return;
}
CopyFile((sSourceDir + sFontFileName),(sFontDir + sFontFileName),FALSE);
BOOL Result;
Result = AddFontResource(sFontDir + sFontFileName);
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)
{
//*** SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts 已存在***"
}
int sFontFileNameLength=(sFontFileName.GetLength())*2;
const BYTE* you=(CONST BYTE*)((LPCTSTR)sFontFileName);
RegSetValueEx(
phkResult,
sFontName,
0,
REG_SZ,
you,
sFontFileNameLength
);
RegCloseKey(phkResult);
::SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0);
}
安装 emoji 字体
最新推荐文章于 2024-09-07 15:34:08 发布