Discussion Community

IT Acumens Forum => Programming Discussions for Engineers => Programming in "Vc++" => Topic started by: sukishan on Jul 12, 2009, 11:08 PM

Title: Command Messages: VC++
Post by: sukishan on Jul 12, 2009, 11:08 PM
Command Messages


One of the main features of a graphical application is to present Windows controls and resources that allow the user to interact with the machine. Examples of controls that we will learn are buttons, list boxes, combo boxes, etc. One type of resource we introduced in the previous lesson is the menu. Such controls and resources can initiate their own messages when the user clicks them. A message that emanates from a Windows control or a resource is called a command message.

Creating a Command Message.
You can start by declaring a framework method. Here is an example:

afx_msg void OnLetItGo();Then you can define the method as you see fit:

void CMainFrame::OnLetItGo()
    // Something to do here
The framework allows you to associate a member function to a command message. This is done using the ON_COMMAND macro. Its syntax:

ON_COMMAND(IDentifier, MethodName);The first argument, IDentifier, of this macro must be the identifier of the menu item or Windows control you want to associate with a method. The second argument, MethodName, must be the name of the member function that will implement the action of the menu item or Windows control such as a button. Imagine you have a menu item Identified as ID_ACTION_LETITGO that you want to associate with the above OnLetItGo() method. You can use the ON_COMMAND macro as follows:

END_MESSAGE_MAP()In the same way, you can create as many command messages as necessary.