Rediger

Del via


ICommandSource Interface

Manages commands sent from a command source object to a user control.

Syntax

interface class ICommandSource

Members

Public Methods

Name Description
ICommandSource::AddCommandHandler Adds a command handler to a command source object.
ICommandSource::AddCommandRangeHandler Adds a group of command handlers to a command source object.
ICommandSource::AddCommandRangeUIHandler Adds a group of user interface command message handlers to a command source object.
ICommandSource::AddCommandUIHandler Adds a user interface command message handler to a command source object.
ICommandSource::PostCommand Posts a message without waiting for it to be processed.
ICommandSource::RemoveCommandHandler Removes a command handler from a command source object.
ICommandSource::RemoveCommandRangeHandler Removes a group of command handlers from a command source object.
ICommandSource::RemoveCommandRangeUIHandler Removes a group of user interface command message handlers from a command source object.
ICommandSource::RemoveCommandUIHandler Removes a user interface command message handler from a command source object.
ICommandSource::SendCommand Sends a message and waits for it to be processed before returning.

Remarks

When you host a user control in an MFC View, CWinFormsView Class routes commands and update command UI messages to the user control to allow it to handle MFC commands (for example, frame menu items and toolbar buttons). By implementing ICommandTarget Interface, you give the user control a reference to the ICommandSource object.

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

For more information on using Windows Forms, see Using a Windows Form User Control in MFC.

Requirements

Header: afxwinforms.h (defined in assembly atlmfc\lib\mfcmifc80.dll)

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.

ICommandSource::AddCommandRangeHandler

Adds a group of command handlers to a command source object.

void AddCommandRangeHandler(
    unsigned int cmdIDMin,
    unsigned int cmdIDMax,
    CommandHandler^ cmdHandler);

Parameters

cmdIDMin
The beginning index of the command ID range. cmdIDMax
The ending index of the command ID range. cmdHandler
A handle to the message handler method to which the commands are mapped.

Remarks

This method maps a contiguous range of command IDs to a single message handler and adds it to the command source object. This is used for handling a group of related buttons with one method.

ICommandSource::AddCommandRangeUIHandler

Adds a group of user interface command message handlers to a command source object.

void AddCommandRangeUIHandler(
    unsigned int cmdIDMin,
    unsigned int cmdIDMax,
    CommandUIHandler^ cmdUIHandler);

Parameters

cmdIDMin
The beginning index of the command ID range. cmdIDMax
The ending index of the command ID range. cmdHandler
A handle to the message handler method to which the commands are mapped.

Remarks

This method maps a contiguous range of command IDs to a single user interface command message handler and adds it to the command source object. This is used for handling a group of related buttons with one method.

ICommandSource::AddCommandUIHandler

Adds a user interface command message handler to a command source object.

void AddCommandUIHandler(
    unsigned int cmdID,
    CommandUIHandler^ cmdUIHandler);

Parameters

cmdID
The command ID. cmdUIHandler
A handle to the user interface command message handler method.

Remarks

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

ICommandSource::PostCommand

Posts a message without waiting for it to be processed.

void PostCommand(unsigned int command);

Parameters

command
The command ID of the message to be posted.

Remarks

This method asynchronously posts the message mapped to the ID specified by command. It calls CWnd::PostMessage to place the message in the window's message queue and then returns without waiting for the corresponding window to process the message.

ICommandSource::RemoveCommandHandler

Removes a command handler from a command source object.

void RemoveCommandHandler(unsigned int cmdID);

Parameters

cmdID
The command ID.

Remarks

This method removes the command handler mapped to cmdID from the command source object.

ICommandSource::RemoveCommandRangeHandler

Removes a group of command handlers from a command source object.

void RemoveCommandRangeUIHandler(
    unsigned int cmdIDMin,
    unsigned int cmdIDMax);

Parameters

cmdIDMin
The beginning index of the command ID range. cmdIDMax
The ending index of the command ID range.

Remarks

This method removes a group of message handlers, mapped to the command IDs specified by cmdIDMin and cmdIDMax, from the command source object.

ICommandSource::RemoveCommandRangeUIHandler

Removes a group of user interface command message handlers from a command source object.

void RemoveCommandRangeUIHandler(
    unsigned int cmdIDMin,
    unsigned int cmdIDMax);

Parameters

cmdIDMin
The beginning index of the command ID range. cmdIDMax
The ending index of the command ID range.

Remarks

This method removes a group of user interface command message handlers, mapped to the command IDs specified by cmdIDMin and cmdIDMax, from the command source object.

ICommandSource::RemoveCommandUIHandler

Removes a user interface command message handler from a command source object.

void RemoveCommandUIHandler(unsigned int cmdID);

Parameters

cmdID
The command ID.

Remarks

This method removes the user interface command message handler mapped to cmdID from the command source object.

ICommandSource::SendCommand

Sends a message and waits for it to be processed before returning.

void SendCommand(unsigned int command);

Parameters

command
The command ID of the message to be sent.

Remarks

This method synchronously sends the message mapped to the ID specified by command. It calls CWnd::SendMessage to place the message in the window's message queue and waits until that window procedure has processed the message before returning.

See also

How to: Add Command Routing to the Windows Forms Control
ICommandTarget Interface