Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

EnumFontFamiliesEx() ???

192 views
Skip to first unread message

Otter

unread,
Oct 28, 1999, 3:00:00 AM10/28/99
to
The EnumFontFamiliesEx() function requires a callback function. I have no
experience writing them and can find no decent exmples. Can anyone send me
anything that describes this process as related to the EnumFontFamiliesEx()
function? i.e. an example of EnumFontFamProc() or EnumFontFamExProc()???
Thanks
Lito
--

Matthias Abraham

unread,
Oct 29, 1999, 3:00:00 AM10/29/99
to
Otter wrote:

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

Gabriel Zerbib

unread,
Oct 31, 1999, 2:00:00 AM10/31/99
to
Don't be afraid by the word callback.
You must view the thing as a procedure the system will call for each element it enumerates.
 
In Visual Basic you could compare to something like :
 
Dim e As Variant
 
For Each e In FontFamilies
    Call DoSomethingWithAFont(e)
Next e
 
You just provide that function, in the call to EnumFontFamiliesEx() :
int CALLBACK DoSomethingWithAFont(
  ENUMLOGFONTEX *,    // logical-font data
  NEWTEXTMETRICEX *,  // physical-font data
  int,                // type of font
  LPARAM               // application-defined data
);
0 new messages