Share via


ICommandSource::AddCommandHandler

Adds a command handler to a command source object.

void AddCommandHandler(
   unsigned int cmdID,
   CommandHandler^ cmdHandler
);

Parameters

  • cmdID
    The command ID.

  • cmdHandler
    A handle to the command handler method.

Remarks

This method adds the command handler cmdHandler to the command source object and maps the handler to cmdID.

See How to: Add Command Routing to the Windows Forms Control for an example of how to use AddCommandHandler.

Example

The following code adds a new command handler method called singleMenuHandler to the command source object m_CmdSrc.

private ICommandSource m_CmdSrc;
public void Initialize (ICommandSource cmdSrc)
{
   m_CmdSrc = cmdSrc;
   // substitue ID of your command (from MFC project's resource.h) for 32771 
   m_CmdSrc.AddCommandHandler(32771, new CommandHandler(singleMenuHandler));
}

Requirements

Header: afxwinforms.h

See Also

Reference

ICommandSource Interface

ICommandSource::RemoveCommandHandler