I want to write the following function
bool IsFontExistInSystem(const CString& fontStyle) const
{
}
Is there any API in windows to do this? Many Thanks!
I want to write the following function
bool IsFontExistInSystem(const CString& fontStyle) const
{
}
Is there any API in windows to do this? Many Thanks!
You could use EnumFontFamiliesEx
to find whether exist actual font.
UPD: I've just learned that it is recommended by MS to use EnumFontFamiliesEx instead of EnumFontFamilies.
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;
}