I hope the following example code fragment will give you a clue; it enumerates
all available font face names and lists them (the whole project is based around
a SDI MFC app with one list view):
int CEnumFontsTestView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CListView::OnCreate(lpCreateStruct) == -1)
return -1;
// set list view to report mode
CListCtrl& lc = GetListCtrl();
DWORD dwStyle = GetWindowLong(lc.GetSafeHwnd(), GWL_STYLE);
dwStyle &= ~(LVS_TYPEMASK | LVS_TYPESTYLEMASK);
dwStyle |= (LVS_REPORT | LVS_SORTASCENDING |
LVS_NOSORTHEADER);
SetWindowLong(lc.GetSafeHwnd(), GWL_STYLE, dwStyle);
lc.InsertColumn(0, _T("Face Name"), LVCFMT_LEFT, 400);
CWindowDC dc(NULL); // you should replace this with a
// printer DC if you want
// to enumerate printer fonts (I think)
LOGFONT lf;
lf.lfCharSet = ANSI_CHARSET;
strcpy(lf.lfFaceName, "");
lf.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
EnumFontFamiliesEx(dc.GetSafeHdc(), &lf,
(FONTENUMPROC)_EnumFontFamExProc, (LPARAM)(LPVOID)this, 0);
return 0;
}
// note: this function must be static, so we pass the 'this'
// pointer as the lParam value
int CALLBACK CEnumFontsTestView::_EnumFontFamExProc(ENUMLOGFONTEX * lpelfe,
NEWTEXTMETRICEX * lpntme, int nFontType, LPARAM lParam)
{
CEnumFontsTestView *pThis =
(CEnumFontsTestView*)(LPVOID)lParam;
TCHAR szFont[LF_FACESIZE];
strcpy(szFont, lpelfe->elfLogFont.lfFaceName);
CListCtrl& lc = pThis->GetListCtrl();
LV_ITEM lvi;
ZeroMemory(&lvi, sizeof(lvi));
lvi.mask = LVIF_TEXT;
lvi.iItem = lc.GetItemCount();
lvi.pszText = szFont;
lc.InsertItem(&lvi);
return 1;
}
--
Matthias Abraham
Wolfson College, Oxford University
matthias...@wolfson.ox.ac.uk
int CALLBACK DoSomethingWithAFont( ENUMLOGFONTEX *, // logical-font data NEWTEXTMETRICEX *, // physical-font data int, // type of font LPARAM // application-defined data );