Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does 'afx_msg' do? - MFC

Tags:

c++

mfc

Disclaimer: I'm new to MFC and have basic knowledge of c++

My question:

I ran into the following code that was auto generated by Visual studio:

afx_msg void OnBnClickedOk();

what does afx_msg do and are there other like that?


As far as my knowledge goes, there are only a handful of access specifiers like : public, private, protected. There's also virtual.

I found an answer here but it is still not clear to me.

like image 533
Rana Avatar asked Feb 10 '16 16:02

Rana


2 Answers

afx_msg is an empty macro #define'd in afxwin.h:

// Type modifier for message handlers
#ifndef afx_msg
#define afx_msg         // intentional placeholder
#endif

The code will compile and work the same with or without afx_msg, but it is used by convention as an indicator that the function is a message handler, and is required if using the class wizard, per TN006: Message Maps:

ClassWizard requires that you use the afx_msg keyword in your message map handler declarations.

like image 145
dxiv Avatar answered Oct 09 '22 05:10

dxiv


The code in afxwin.h is just:

// Type modifier for message handlers
#ifndef afx_msg
#define afx_msg         // intentional placeholder
#endif

it is, or might have been, a help for the wizards to recognize the code.

It doesn't do anything else.

like image 41
Bo Persson Avatar answered Oct 09 '22 07:10

Bo Persson