시스템에 MFC에 필요한 글꼴이 있는지 여부를 찾는 방법에 어떻게?
문제
다음 기능을 작성하고 싶습니다
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가 enumfontfamilies 대신 enumfontfamiliesex를 사용하는 것이 좋습니다.
제휴하지 않습니다 StackOverflow