VC枚举系统所有字体

来源:互联网 发布:开元知海e读 编辑:程序博客网 时间:2024/05/18 02:30
LOGFONT lf;
lf.lfCharSet = DEFAULT_CHARSET; // Initialize the LOGFONT structure
strcpy(lf.lfFaceName,"");
CClientDC dc (this);

//Enumerate the font families
::EnumFontFamiliesEx((HDC) dc,&lf,
(FONTENUMPROC) EnumFontFamProc,(LPARAM) this,0);

//枚举函数
int CALLBACK EnumFontFamProc(LPENUMLOGFONT lpelf,LPNEWTEXTMETRIC lpntm,DWORD nFontType,long lparam)
{
    // Create a pointer to the dialog window
    CDay7Dlg* pWnd = (CDay7Dlg*) lparam;
    // add the font name to the list box

    pWnd ->m_ctlFontList.AddString(lpelf ->elfLogFont.lfFaceName);

    // Return 1 to continue font enumeration
    return 1;
}

其中m_ctlFontList是一个列表控件变量  原帖链接:点击打开链接


对于CALLBACK 函数使用方法如下:

头文件定义:

1
static int CALLBACK EnumFontFamProc(LPENUMLOGFONT lpelf,LPNEWTEXTMETRIC lpntm,DWORD nFontType,long lparam);

cpp文件中:

1
2
3
int _stdcall XXX::EnumFontFamProc(LPENUMLOGFONT lpelf,LPNEWTEXTMETRIC lpntm,DWORD nFontType,long lparam)
{
}

0 0
原创粉丝点击