ICommandSource Interface

管理从命令源对象发送到用户控件的命令。

Syntax

interface class ICommandSource

Members

Public Methods

Name Description
ICommandSource::AddCommandHandler 将命令处理程序添加到命令源对象。
ICommandSource::AddCommandRangeHandler 将一组命令处理程序添加到命令源对象。
ICommandSource::AddCommandRangeUIHandler 将一组用户界面命令消息处理程序添加到命令源对象。
ICommandSource::AddCommandUIHandler 将用户界面命令消息处理程序添加到命令源对象。
ICommandSource::PostCommand 发布消息时不等待处理消息。
ICommandSource::RemoveCommandHandler 从命令源对象中移除命令处理程序。
ICommandSource::RemoveCommandRangeHandler 从命令源对象中移除一组命令处理程序。
ICommandSource::RemoveCommandRangeUIHandler 从命令源对象中移除一组用户界面命令消息处理程序。
ICommandSource::RemoveCommandUIHandler 从命令源对象中移除用户界面命令消息处理程序。
ICommandSource::SendCommand 发送消息并等待进行处理后再返回。

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.

有关如何使用 的示例,请参阅ICommandTarget

有关使用 Windows 窗体的详细信息,请参阅在 MFC 中使用 Windows 窗体用户控件

Requirements

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

ICommandSource::AddCommandHandler

将命令处理程序添加到命令源对象。

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

Parameters

cmdID
命令 ID。

cmdHandler
命令处理程序方法的句柄。

Remarks

此方法将命令处理程序 cmdHandler 添加到命令源对象,并将处理程序映射到 cmdID。 有关如何使用 AddCommandHandler 的示例,请参阅如何:将命令路由添加到 Windows 窗体控件

ICommandSource::AddCommandRangeHandler

将一组命令处理程序添加到命令源对象。

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

Parameters

cmdIDMin
命令 ID 范围的起始索引。

cmdIDMax
命令 ID 范围的结束索引。

cmdHandler
命令映射到的消息处理程序方法的句柄。

Remarks

此方法将连续的命令 ID 范围映射到单个消息处理程序,并将其添加到命令源对象。 这用于通过一个方法处理一组相关按钮。

ICommandSource::AddCommandRangeUIHandler

将一组用户界面命令消息处理程序添加到命令源对象。

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

Parameters

cmdIDMin
命令 ID 范围的起始索引。

cmdIDMax
命令 ID 范围的结束索引。

cmdHandler
命令映射到的消息处理程序方法的句柄。

Remarks

此方法将连续的命令 ID 范围映射到单个用户界面命令消息处理程序,并将其添加到命令源对象。 这用于通过一个方法处理一组相关按钮。

ICommandSource::AddCommandUIHandler

将用户界面命令消息处理程序添加到命令源对象。

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

Parameters

cmdID
命令 ID。

cmdUIHandler
用户界面命令消息处理程序方法的句柄。

Remarks

此方法将用户界面命令消息处理程序 cmdHandler 添加到命令源对象,并将处理程序映射到 cmdID。

ICommandSource::PostCommand

发布消息时不等待处理消息。

void PostCommand(unsigned int command);

Parameters

command
要发布的消息的命令 ID。

Remarks

此方法以异步方式发布映射到命令指定的 ID 的消息。 它调用 CWnd::PostMessage 将消息置于窗口的消息队列中,然后返回时不等待相应的窗口处理消息。

ICommandSource::RemoveCommandHandler

从命令源对象中移除命令处理程序。

void RemoveCommandHandler(unsigned int cmdID);

Parameters

cmdID
命令 ID。

Remarks

此方法从命令源对象中移除映射到 cmdID 的命令处理程序。

ICommandSource::RemoveCommandRangeHandler

从命令源对象中移除一组命令处理程序。

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

Parameters

cmdIDMin
命令 ID 范围的起始索引。

cmdIDMax
命令 ID 范围的结束索引。

Remarks

此方法从命令源对象中移除一组消息处理程序,这些处理程序映射到 cmdIDMin 和 cmdIDMax 指定的命令 ID。

ICommandSource::RemoveCommandRangeUIHandler

从命令源对象中移除一组用户界面命令消息处理程序。

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

Parameters

cmdIDMin
命令 ID 范围的起始索引。

cmdIDMax
命令 ID 范围的结束索引。

Remarks

此方法从命令源对象中移除一组用户界面命令消息处理程序,这些处理程序映射到 cmdIDMin 和 cmdIDMax 指定的命令 ID。

ICommandSource::RemoveCommandUIHandler

从命令源对象中移除用户界面命令消息处理程序。

void RemoveCommandUIHandler(unsigned int cmdID);

Parameters

cmdID
命令 ID。

Remarks

此方法从命令源对象中移除映射到 cmdID 的用户界面命令消息处理程序。

ICommandSource::SendCommand

发送消息并等待进行处理后再返回。

void SendCommand(unsigned int command);

Parameters

command
要发送的消息的命令 ID。

Remarks

此方法同步发送映射到命令指定的 ID 的消息。 它调用 CWnd::SendMessage 将消息置于窗口的消息队列中,并等待该窗口过程处理消息之后再返回。

See also

如何:向 Windows 窗体控件添加命令传送
ICommandTarget Interface