我想写下面的函数
bool IsFontExistInSystem(const CString& fontStyle) const { }
有没有在Windows中的任何API来做到这一点? 非常感谢!
这是我挖掘出来的一些旧代码,它将检查是否安装了字体。 它可以做整理,但你有这个想法:
static int CALLBACK CFontHelper::EnumFontFamExProc(ENUMLOGFONTEX* /*lpelfe*/, NEWTEXTMETRICEX* /*lpntme*/, int /*FontType*/, LPARAM lParam) { LPARAM* l = (LPARAM*)lParam; *l = TRUE; return TRUE; } bool Font::IsInstalled(LPCTSTR lpszFont) { // Get the screen DC CDC dc; if (!dc.CreateCompatibleDC(NULL)) { return false; } LOGFONT lf = { 0 }; // Any character set will do lf.lfCharSet = DEFAULT_CHARSET; // Set the facename to check for _tcscpy(lf.lfFaceName, lpszFont); LPARAM lParam = 0; // Enumerate fonts ::EnumFontFamiliesEx(dc.GetSafeHdc(), &lf, (FONTENUMPROC)EnumFontFamExProc, (LPARAM)&lParam, 0); return lParam ? true : false; }
您可以使用EnumFontFamiliesEx
来查找是否存在实际的字体。
UPD:我刚刚了解到MS建议使用EnumFontFamiliesEx而不是EnumFontFamilies。