调用临时Fonts
系统Windows\Fonts找不到,没法了,自己在EXE目录下建一个Fonts目录,直接临时调用:
1.
int XXX::InstallTempFont() { wchar_t path[MAX_PATH]; GetModuleFileName(NULL,path,MAX_PATH); CString szPath = path; int nFind = szPath.ReverseFind('\\'); szPath = szPath.Left(nFind) + TEXT("\\Fonts\\TruthCYR-Regular.otf"); return AddFontResourceEx(szPath, FR_PRIVATE, 0);} void XXX::UnstallTempFont() { wchar_t path[MAX_PATH]; GetModuleFileName(NULL,path,MAX_PATH); CString szPath = path; int nFind = szPath.ReverseFind('\\'); szPath = szPath.Left(nFind) + TEXT("\\Fonts\\TruthCYR-Regular.otf"); RemoveFontResourceEx(szPath, FR_PRIVATE, 0);}2.
HINSTANCE hResInstance = AfxGetResourceHandle(); HRSRC res = FindResource(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_FONT_PHONETIC), _T("BINARY")); if (res) { HGLOBAL mem = ::LoadResource(hResInstance, res); void *data = ::LockResource(mem); DWORD len = ::SizeofResource(hResInstance, res); DWORD nFonts = 0; HANDLE hFont = AddFontMemResourceEx( data, // font resource len, // number of bytes in font resource NULL, // Reserved. Must be 0. &nFonts); // number of fonts installed if (!hFont) { AfxMessageBox(_T("字体加载失败!")); } }
不要使用AddFontResource!!!!!!!!!!!!!!!!!!!