I searched but I didn't found. I want a Message map macro that links the menu item command action to a function accepting the numeric ID and providing no return at all (being void).
ON_COMMAND
returns void, but it is too limited, because it does not provide the menu item ID, which I need in this case.
ON_COMMAND_EX
returns a BOOL
, so it forces me to do a lot of returns, which would be unneeded if the return type was void.
So, as I described in first paragraph, is there such a macro?
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
, replacingBOOL
byvoid
.The
ON_COMMAND_EX
macro is:I've just copied and adapted it to my own purposes:
Notice the only two changes are the name of tha macro and change from
BOOL
tovoid
To use it: On the message map, add something like
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:
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