[英]How to find whether system has the font I needed in MFC?
I want to write the following function 我想写下面这个函数
bool IsFontExistInSystem(const CString& fontStyle) const
{
}
Is there any API in windows to do this? Windows中是否有任何API可以执行此操作? Many Thanks!
非常感谢!
Here's some old code I dug out that will check if a font is installed. 这是我挖出的一些旧代码,它将检查是否安装了字体。 It could do with being tidied up but you get the idea:
这可以通过整理来实现,但你明白了:
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;
}
You could use EnumFontFamiliesEx
to find whether exist actual font. 您可以使用
EnumFontFamiliesEx
查找是否存在实际字体。
UPD: I've just learned that it is recommended by MS to use EnumFontFamiliesEx instead of EnumFontFamilies. UPD:我刚刚了解到MS建议使用EnumFontFamiliesEx而不是EnumFontFamilies。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.