MFC Message Trap - What's the Difference?

I'm just curious that (if there is) the difference between the two two message traps in MFC for the OnSize (..) function.

1 - Via the message card:

BEGIN_MESSAGE_MAP(CClassWnd, CBaseClassWnd)
...
    ON_WM_SIZE()
..
END_MESSAGE_MAP()

2 - Via afx_message:

afx_msg type OnSize(...);

They seem to be used interchangeably, which one should be used or depends on other factors?

+5
source share
3 answers

Both parts are required to add a message handler to the class. A message map must be declared inside your class along with declarations for any message handler functions (for example, OnSize).

class CClassWnd : public CBaseClassWnd {
    ...
    afx_msg void OnSize(UINT nType, int cx, int cy);
    DECLARE_MESSAGE_MAP
};

afx_msg - it's just an empty placeholder macro - it actually does nothing, but is always included in the agreement.

.cpp :

BEGIN_MESSAGE_MAP(CClassWnd, CBaseClassWnd)
    ON_WM_SIZE()
END_MESSAGE_MAP()

, , , . ON_WM_SIZE wParam lParam WM_SIZE (nType, cx cy ). MFC (WM_LBUTTONDOWN, WM_DESTROY ..).

, MFC MSDN.

+12

afx_msg - , , MFC . afx_msg .

+3

Windows MFC, .

, CWnd ( MFC) Windows (.. ON_WM_DRAWITEM, ON_WM_MEASUREITEM, ON_WM_ENTERIDLE .. ..).

, MFC, , , .

0

All Articles