Jump to content
  • Advertisement
Sign in to follow this  
BattleMetalChris

EnumFontFamiliesEx only finds one font

This topic is 2535 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to get an enumeration of all the installed fonts.

I create a LOGFONT instance, initialise the member variables that EnumFontFamiliesEx uses and then call EnumFontFamiliesEx, passing the current device context, a reference to the LOGFONT, a handler callback function and NULL the other arguments.


void AppClass::loadFont(std::string fontName)
{
// fontName not used yet as just testing
LOGFONT logFont;
ZeroMemory(&logFont, sizeof(LOGFONT));
logFont.lfCharSet = DEFAULT_CHARSET;
strcpy(logFont.lfFaceName, "");
logFont.lfPitchAndFamily = 0;

EnumFontFamiliesEx(GetDC(m_hWnd), &logFont, (FONTENUMPROC)AppClass::EnumFontProc, NULL, NULL);

}


My handler function for the moment just collects the enumerated fonts' names into a static vector of strings, so I can test if it's all working:


int CALLBACK AppClass::EnumFontProc(ENUMLOGFONT FAR *lpelf, NEWTEXTMETRIC FAR *lpntm, DWORD fontType, LPARAM lParam )
{
m_fontNames.push_back(std::string((TCHAR*)lpelf->elfFullName));

return 0;
}


It compiles, but when EnumFontFamiliesEx is called it only calls EnumFontProc once, for the font 'System'. No others are enumerated.

Can anyone give any clues as to what I'm doing wrong?

Share this post


Link to post
Share on other sites
Advertisement
Your EnumFontProc() function is returning 0. You return 0 if you want to stop. Return a non-0 value to continue enumeration.

Share this post


Link to post
Share on other sites
Bear in mind that your call to EnumFontFamiliesEx leaks the DC from GetDC, and that casting the function pointer is dangerous. For example, the second parameter to the callback functrion isn't guaranteed to point to a [color="#000000"]NEWTEXTMETRIC struct. It's better to use the defined callback format, and cast the parameters inside the function if they're of the correct type.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!