I didn't found such a macro but I came with a solution: Define my own macro based on the definition of ON_COMMAND_EX
, replacing BOOL
by void
.
The ON_COMMAND_EX
macro is:
#define ON_COMMAND_EX(id, memberFxn) \
{ WM_COMMAND, CN_COMMAND, (WORD)id, (WORD)id, AfxSigCmd_EX, \
(AFX_PMSG) \
(static_cast< BOOL (AFX_MSG_CALL CCmdTarget::*)(UINT) > \
(memberFxn)) },
I've just copied and adapted it to my own purposes:
#define ON_COMMAND_EX_VOID(id, memberFxn) \
{ WM_COMMAND, CN_COMMAND, (WORD)id, (WORD)id, AfxSigCmd_EX, \
(AFX_PMSG) \
(static_cast< void (AFX_MSG_CALL CCmdTarget::*)(UINT) > \
(memberFxn)) },
Notice the only two changes are the name of tha macro and change from BOOL
to void
To use it:
On the message map, add something like
ON_COMMAND_EX_VOID(ID_FILE_PREFERENCES, OnFilePreferencesVoid)
Then declare the handler function on the header file:
afx_msg void OnFilePreferencesVoid(UINT nID);
And finally do the implementation on the source code file:
void CMainFrame::OnFilePreferencesVoid(UINT nID)
{
CString s;
s.Format(_T("%d"), nID);
AfxMessageBox(s);
}
Obviously, the code posted here is a theoretical example, as there are more useful things to do than display an already annoying popup message with an irritant resource ID.
The inspiration for the solution came from ON_MESSAGE_VOID
posted on https://stackoverflow.com/a/10619963/383779