GDI枚举字体:
BOOL UIFont::IsInstalled(LPCTSTR lpFontName)
{
AutoDC hDC(::GetDesktopWindow());
if (!hDC) return FALSE;
PairT<LOGFONT,BOOL> FindFont={0};
LOGFONT& logFont=FindFont._Value;
logFont.lfCharSet = DEFAULT_CHARSET;
_tcscpy_s(logFont.lfFaceName,lpFontName);
EnumFontFamiliesEx(hDC, &logFont, (FONTENUMPROC)EnumFamCallBack, (LPARAM)&FindFont,0);
if (FindFont._Value2)
UMyChartLog::LogNormal(_T("[UIFont::IsInstalled] [font=%s] installed."),lpFontName);
else
UMyChartLog::LogWarning(_T("[UIFont::IsInstalled] [font=%s] not installed."),lpFontName);
return FindFont._Value2;
}
int CALLBACK EnumFamCallBack(LPLOGFONT lplf, LPNEWTEXTMETRIC lpntm, DWORD FontType, LPARAM lParam)
{
PairT<LOGFONT,BOOL>* pFindFont=(PairT<LOGFONT,BOOL>*)lParam;
LOGFONT& logFont=pFindFont->_Value;
if (_tcsicmp(lplf->lfFaceName,logFont.lfFaceName)==0)
{
pFindFont->_Value2=TRUE;
return 0;
}
return 1;
}
GDI+枚举字体
BOOL UIPlusFont::IsInstalled(LPCTSTR lpFontName)
{
InstalledFontCollection installedFonts;
int nCount=installedFonts.GetFamilyCount();
if (nCount<=0) return FALSE;
FontFamily* pFontFamily = new FontFamily[nCount];
if (!pFontFamily) return FALSE;
int nFound=0;
installedFonts.GetFamilies(nCount, pFontFamily, &nFound);
TCHAR szFontName[128]={0};
for(int i=0;i<nFound;++i)
{
memset(szFontName,0,sizeof(szFontName));
pFontFamily[i].GetFamilyName(szFontName);
if (_tcscmp(szFontName,lpFontName)==0)
{
UMyChartLog::LogNormal(_T("[UIPlusFont::IsInstalled] [font=%s] installed."),lpFontName);
return TRUE;
}
}
UMyChartLog::LogWarning(_T("[UIPlusFont::IsInstalled] [font=%s] not installed."),lpFontName);
return FALSE;
}