Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2005
Visual Studio
Visual C++
Reference
Libraries Reference
MFC
Macros and Globals
 ON_COMMAND
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2005/.NET Framework 2.0

Other versions are also available for the following:
MFC Library Reference 
ON_COMMAND 

This macro maps a command message to a member function.

ON_COMMAND(id, memberFxn )

Parameters

id

The command ID.

memberFxn

The name of the message-handler function to which the command is mapped.

It indicates which function will handle a command message from a command user-interface object such as a menu item or toolbar button.

When a command-target object receives a Windows WM_COMMAND message with the specified ID, ON_COMMAND will call the member function memberFxn to handle the message.

Use ON_COMMAND to map a single command to a member function. Use ON_COMMAND_RANGE to map a range of command ids to one member function. Only one message-map entry can match a given command id. That is, you can't map a command to more than one handler. For more information and examples, see Message Handling and Mapping Topics.

// example for ON_COMMAND
BEGIN_MESSAGE_MAP( CMyDoc, CDocument )
    ON_COMMAND( ID_MYCMD, OnMyCommand )
    // ... More entries to handle additional commands
END_MESSAGE_MAP( )
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker