Thread: Trouble making a font name list

  1. #1
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470

    Trouble making a font name list

    Hi, i'm trying to fill a CComboBox with the system's font names. This is the callback funtion:

    Code:
    int CALLBACK CWordProcessorDlg::EnumFontFamProc(LPENUMLOGFONT lpelf, LPNEWTEXTMETRIC lpntm, DWORD nFontType, long lParam)
    {
    	m_ccbfontlist.AddString(lpelf->elfLogFont.lfFaceName);
    	return 1;
    }
    This is how i call the CALLBACK:
    Code:
    LOGFONT lf;
    CClientDC dc(this);
    ::EnumFontFamiliesEx((HDC)dc,&lf,(FONTENUMPROC)EnumFontFamProc, (LPARAM)this,0);
    But i get error msg C2440 on EnumFontFamiliesEx():
    Code:
    error C2440: 'type cast' : cannot convert from '' to 'int (__stdcall *)(const struct tagLOGFONTA *,const struct tagTEXTMETRICA *,unsigned long,long)'
    Please help.
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Your EnumFontFamExProc is of the wrong type - you can't use a non-static c++ class member function when what EnumFontFamiliesEx requires is a pointer to a stdcall function returning an int and taking four parameters (your c++ member function comes encumbered with this). Making the c++ class member function in question static is the usual way to resolve this issue.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470
    i think that solved it. Thanks.
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  4. #4
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470
    sorry, but there's another problem. When i make EnumFontFamExProc static, the:
    Code:
    m_ccbfontlist.AddString(lpelf->elfLogFont.lfFaceName);
    call gives error no C2228 : left of '.AddString' must have class/struct/union type". But 'm_ccbfontlist' is of type CComboBox. Why is this?
    Last edited by geek@02; 11-10-2006 at 10:20 AM.
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  5. #5
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    Where is it declared? Is it in the right scope?
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  6. #6
    Android geek@02's Avatar
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    470
    yes, m_ccbfontlist is declared in the correct header file and is in the right scope.
    Above error only happens when i make EnumFontFamExProc a static one. ??
    GameJolt: https://gamejolt.com/@KasunL
    Game Development Youtube:
    https://is.gd/XyhYoP
    Amateur IT Blog: http://everything-geeky.blogspot.com/



    (and, sorry for my amateur English)

  7. #7
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    The static member function can only access globals or other static member functions or data from the same class.

    Pass a pointer to your c++ class as the LPARAM of the EnumFontFamiliesEx (it's the same application defined value that is passed to your EnumFontFamExProc function) and then use that to access member functions.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  3. Sorting linked list please help with CODE
    By scarlet00014 in forum C Programming
    Replies: 3
    Last Post: 09-27-2008, 11:24 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 09:01 AM