Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. EnumFontFamiliesEx only returns one font -- SOLVED

EnumFontFamiliesEx only returns one font -- SOLVED

Scheduled Pinned Locked Moved C / C++ / MFC
c++databasewpfcomalgorithms
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alan Balkany
    wrote on last edited by
    #1

    Hi all, I'm trying to use EnumFontFamiliesEx to get all the fonts on a Windows 7 system, and it only returns one font: "System". I tried to follow the incomplete documentation for this function here: http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k%28%22WINGDI%2fENUMFONTFAMILIESEX%22%29;k%28ENUMFONTFAMILIESEX%29;k%28DevLang-%22C%2B%2B%22%29;k%28TargetOS-WINDOWS%29&rd=true[^] but with no luck. Here's my function (in a dialog-based MFC app):

    void CAllFontsDlg::fillListBoxWithFonts ()
    {
    lb = (CListBox*) GetDlgItem (IDC_LIST1);
    CDC* pDC = GetDC ();
    LOGFONT lf;

    	// To enumerate all styles and charsets of all fonts: 
    lf.lfFaceName\[0\] = '\\0';
    lf.lfCharSet = DEFAULT\_CHARSET;
    HRESULT hr;
    hr = EnumFontFamiliesEx (pDC->m\_hDC, &lf, EnumFontFamExProc, 0, 0);
    

    }

    And here's my callback function (which is called exactly once):

    CListBox* lb;

    int CALLBACK EnumFontFamExProc(
    const LOGFONT *lpelfe,
    const TEXTMETRIC *lpntme,
    DWORD FontType,
    LPARAM lParam)
    {

    lb->AddString (lpelfe->lfFaceName);
    return 0;
    

    }

    Can anyone see what I'm doing wrong? Thanks!

    "Microsoft -- Adding unnecessary complexity to your work since 1987!"

    A 1 Reply Last reply
    0
    • A Alan Balkany

      Hi all, I'm trying to use EnumFontFamiliesEx to get all the fonts on a Windows 7 system, and it only returns one font: "System". I tried to follow the incomplete documentation for this function here: http://msdn.microsoft.com/query/dev10.query?appId=Dev10IDEF1&l=EN-US&k=k%28%22WINGDI%2fENUMFONTFAMILIESEX%22%29;k%28ENUMFONTFAMILIESEX%29;k%28DevLang-%22C%2B%2B%22%29;k%28TargetOS-WINDOWS%29&rd=true[^] but with no luck. Here's my function (in a dialog-based MFC app):

      void CAllFontsDlg::fillListBoxWithFonts ()
      {
      lb = (CListBox*) GetDlgItem (IDC_LIST1);
      CDC* pDC = GetDC ();
      LOGFONT lf;

      	// To enumerate all styles and charsets of all fonts: 
      lf.lfFaceName\[0\] = '\\0';
      lf.lfCharSet = DEFAULT\_CHARSET;
      HRESULT hr;
      hr = EnumFontFamiliesEx (pDC->m\_hDC, &lf, EnumFontFamExProc, 0, 0);
      

      }

      And here's my callback function (which is called exactly once):

      CListBox* lb;

      int CALLBACK EnumFontFamExProc(
      const LOGFONT *lpelfe,
      const TEXTMETRIC *lpntme,
      DWORD FontType,
      LPARAM lParam)
      {

      lb->AddString (lpelfe->lfFaceName);
      return 0;
      

      }

      Can anyone see what I'm doing wrong? Thanks!

      "Microsoft -- Adding unnecessary complexity to your work since 1987!"

      A Offline
      A Offline
      Alan Balkany
      wrote on last edited by
      #2

      Solved my own problem! The "return 0" in the callback function was terminating the enumeration the first time through! My fault...

      "Microsoft -- Adding unnecessary complexity to your work since 1987!"

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups