Поделиться через


ICommandSource::AddCommandHandler

Adds a command handler to a command source object.

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

Параметры

  • cmdID
    The command ID.

  • cmdHandler
    A handle to the command handler method.

Заметки

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.

Пример

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));
}

Требования

Header: afxwinforms.h

См. также

Основные понятия

ICommandSource Interface

ICommandSource::RemoveCommandHandler