网站首页  词典首页

请输入您要查询的计算机术语:

 

术语 CCmdTarget::OnCmdMsg
释义 CCmdTarget::OnCmdMsg

virtual BOOL OnCmdMsg(
     UINT nID,
     int nCode,
     void* pExtra,
     AFX_CMDHANDLERINFO* pHandlerInfo
    );

返回值:如果消息被处理了,则返回非零值;否则为0。

参数:
nID命令的ID。
nCode命令的通知代码。
pExtra根据nCode的值使用。
pHandlerInfo如果非空,OnCmdMsg将填充pHandlerInfo 结构的pTarget和pmf成员,而不是分派该命令。此参数通常为NULL。

说明:
本函数由框架来调用,它分派命令并处理那些提供了命令用户接口的对象的更新。这是框架的命令体系中实现的一个主要例程。
在运行时,OnCmdMsg把命令分派到其它对象上或者调用CCmdTarget::OnCmdMsg(此函数进行真正的消息映射查找)自己处理命令。有关这个缺省命令例程的完整描述,请参阅联机文档“Visual C++程序员指南”中的“消息处理”和“映射主题”部分。
偶尔需要覆盖本函数以扩展MFC框架的标准命令例程。有关命令例程体系中的更多细节,请参阅联机文档中的“技术指南21”。

示例:
//This example illustrates extending the framework's standard command
//route from the view to objects managed by the view. This example
//is from an object-oriented drawing application, similar to the
//DRAWCLI sample application, which draws and edits "shapes".
BOOL CMyView::OnCmdMsg(UINT nID, int nCode, void* pExtra,
                        AFX_CMDHANDLERINFO* pHandlerInfo )
{
  //Extend the framework's command route from the view to
  //the application-specific CMyShape that is currently selected.
  //in the view. m_pActiveShape is NULL if no shape object
  //is currently selected in the view.
  if( (m_pActiveShape!=NULL)&&
       m_pActiveShape->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo
    ) )
  return TRUE;

  //If the object(s) in the extended command route don't handle
  //the command, then let the base class OnCmdMsg handle it.
  return CView::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo );
}

//The command handler for ID_SHAPE_COLOR  (menu command used to change
//the color of the currently selected shape ) was added to
//the message map of CMyShape (note, not CMyView ) using ClassWizzard.
//The menu item will be automatically enabled or disabled, depending
//on whether a CMyShape is currently selected in the view, that is
//depending on whether CMyView::m_pActiveView is NULL. It is not
//necessary to implement an ON_UPDATE_COMMAND_UI handler to enable
//or disable the menu item.
BEGIN_MESSAGE_MAP( CMyShape, CCmdTarget )
//{{AFX_MSG_MAP( CMyShape )
    ON_COMMAND( ID_SHAPE_COLOR, OnShapeColor )
//}}AFX_MSG_MAP( )
END_MESSAGE_MAP( )

请参阅:CCmdUI
随便看

 

MFC类库中文详解手册包含4274条MFC类库参考词条,基本涵盖了Microsoft基本类库中的类、全局函数、全局变量和宏的内容,是计算机编程的有利工具。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 12:30:09