c++mfcafx

What is private MFC and why are they not accessible through the normal interface?


I am using MFC for gui development and I stumbled upon a function that could be useful for what I'm trying to do. The function is _AfxCompareClassName. However, it is included in the file "afximpl.h" which is located in the directory "VC/altmfc/src/mfc/afximpl.h". Normal mfc includes are in the directory "VC/atlmfc/include".

Now from what I've gathered those files and functions located in src/mfc are considered private mfc (according to this guy) and I shouldn't use them. Why ? This function does look nice. It would help me know where in the UI I am currently.

Ultimately what I wanted to do was to change the escape/return keys behavior when editing a field of text (Edit Control). My questions are the following :

I though it'd be nice to get some info about private MFC since there doesn't seem to be any on SO so far.

Thanks a lot, JC


Solution

  • The 'private' MFC files are the implementation details of MFC. Just as you wouldn't want or expect users of your classes to get at the private: data or methods, you shouldn't rely on the MFC implementation-level utility code. Note that almost any cool thing you can find in the MFC implementation details is available publicly -- somewhere. You just have to dig.

    There is built-in functionality in MFC that does what you want. It's called RUNTIME_CLASS, and here's sample code from MSDN:

    // Example for RUNTIME_CLASS
    CRuntimeClass* prt = RUNTIME_CLASS( CAge );
    ASSERT( lstrcmp( prt->m_lpszClassName, "CAge" )  == 0 );