c++ 枚举系统字体

//1、定义: CStringArray m_mSysFonts;
//2、回调: static INT CALLBACK NEnumFontNameProc(LOGFONT *plf, TEXTMETRIC* /*ptm*/, INT /*nFontType*/, LPARAM lParam/**/);
HDC hdc = ::GetDC(*this);
int nRet = ::EnumFontFamilies(hdc, (LPTSTR) NULL, (FONTENUMPROC)NEnumFontNameProc,(LPARAM)&(m_mSysFonts));
if (nRet != 0)
{
for (int i = 0; i< m_mSysFonts.GetCount(); i++)
{
// do sth;
}
}

::ReleaseDC(*this, hdc);  



//枚举系统字体
3、INT CALLBACK CEmunFontsDlg::NEnumFontNameProc(LOGFONT *plf, TEXTMETRIC* /*ptm*/, INT /*nFontType*/, LPARAM lParam/**/)
{
//同步调用的回调!! 在同一个线程
CStringArray* sysFonts = (CStringArray*) lParam;


if (sysFonts != NULL)
{
sysFonts->Add(CString(plf->lfFaceName));
}


return TRUE; //EnumFontFamilies 返回值由此回调返回决定
}

猜你喜欢

转载自blog.csdn.net/jangdong/article/details/80729112