tags:

views:

69

answers:

2

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 :

  • What is a private MFC function ?
  • Why shouldn't I use those functions (From what I have gathered they change often, so it is why I shouldn't use them. Is there another reason?)
  • Is there a cleaner way to do what I'm looking to do ?

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

+2  A: 

It's "private" as it's located in the source tree rather than the external includes folder.

You shouldn't use functions defined in these files as they are internal to the implementation of MFC and could well change.

If you really need the functionality you could copy the code (with adequate attribution) and put it into one of your classes, though this is far from ideal. I'd rename the function too.

ChrisF
+4  A: 

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 );
John Dibling