Trouble making a font name list

This is a discussion on Trouble making a font name list within the Windows Programming forums, part of the Platform Specific Boards category; Hi, i'm trying to fill a CComboBox with the system's font names. This is the callback funtion: Code: int CALLBACK ...

  1. #1
    Android
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    362

    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.
    Some useless programs i've wrote : slprogrammersheaven
    Youtube: http://www.youtube.com/user/geekyzine
    My amature IT Blog: http://everything-geeky.blogspot.com/
    My Flash games: http://flashweed.blogspot.com/

    (and, sorry for my amature 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
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    362
    i think that solved it. Thanks.
    Some useless programs i've wrote : slprogrammersheaven
    Youtube: http://www.youtube.com/user/geekyzine
    My amature IT Blog: http://everything-geeky.blogspot.com/
    My Flash games: http://flashweed.blogspot.com/

    (and, sorry for my amature english)

  4. #4
    Android
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    362
    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 09:20 AM.
    Some useless programs i've wrote : slprogrammersheaven
    Youtube: http://www.youtube.com/user/geekyzine
    My amature IT Blog: http://everything-geeky.blogspot.com/
    My Flash games: http://flashweed.blogspot.com/

    (and, sorry for my amature 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
    Join Date
    Mar 2004
    Location
    Kurunegala Colony, Sri Lanka, Sri Lanka
    Posts
    362
    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. ??
    Some useless programs i've wrote : slprogrammersheaven
    Youtube: http://www.youtube.com/user/geekyzine
    My amature IT Blog: http://everything-geeky.blogspot.com/
    My Flash games: http://flashweed.blogspot.com/

    (and, sorry for my amature 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, 03: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, 08:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21