如何查找系统是否具有我在MFC中需要的字体?

use*_*749 5 c++ windows fonts mfc system

我想写下面这个函数

bool IsFontExistInSystem(const CString& fontStyle) const
{

}
Run Code Online (Sandbox Code Playgroud)

Windows中是否有任何API可以执行此操作?非常感谢!

Rob*_*Rob 6

这是我挖出的一些旧代码,它将检查是否安装了字体.这可以通过整理来实现,但你明白了:

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;
}
Run Code Online (Sandbox Code Playgroud)