When do you use ON_COMMAND and when do we use ON_MESSAGE. What are the differences between them.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
ON_COMMANDis specifically used to handle a command message (i.e.WM_COMMAND) like the click of a button/menu item/toolbar button.ON_MESSAGEis more generic and can be used for any windows message. It is usually used for less frequently handled messages for which specific message map macros have not been provided. You can useON_MESSAGEto handleON_COMMANDmessages as well but you will have to extract message information (i.e. command ID) yourself.Example:
See here:
In the message map:
The handler:
Disclaimer: Owing to MFC’s message pump mechanism, you may have to do a bit more than what’s shown above. The best man to ask: Jeff Prosise