CCmdTarget::OnCmdMsg

Llamado por el marco para distribuir y enviar mensajes de comando y controlar la actualización de los objetos de la interfaz de usuario del comando.

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

Parámetros

  • nID
    Contiene el identificador de comando

  • nCode
    Identifica el código de notificación de comando.Vea Comentarios para obtener más información sobre los valores para nCode.

  • pExtra
    Se utiliza como el valor de nCode.Vea Comentarios para obtener más información sobre pExtra.

  • pHandlerInfo
    Si no NULL, OnCmdMsg completa a los miembros de pTarget y de pmf de la estructura de pHandlerInfo en lugar de enviar el comando.Normalmente, este parámetro debe ser NULL.

Valor devuelto

Distinto de cero si se procesa el mensaje; si no 0.

Comentarios

Ésta es la rutina principal de implementación de la arquitectura del marco.

En tiempo de ejecución, OnCmdMsg envía un comando a otros objetos o controla el propio comando llamando a la clase CCmdTarget::OnCmdMsgraíz, que hace que la búsqueda real de mapa de mensajes.Para obtener una descripción completa de enrutamiento predeterminado del comando, vea Temas del control de mensajes y de asignación.

En raras ocasiones, quizás desee invalidar esta función miembro para extender el enrutamiento estándar del marco.Hace referencia a nota técnica 21 para detalles avanzadas de la arquitectura de comando-enrutamiento.

Si reemplaza OnCmdMsg, debe proporcionar el valor adecuado para nCode, el código de notificación de comando, y pExtra, que depende del valor de nCode.La tabla siguiente se enumeran los valores correspondientes:

Valor de nCode

Valor de pExtra

CÓDIGO

CCmdUI*

CN_EVENT

AFX_EVENT*

CN_UPDATE_COMMAND_UI

CCmdUI*

CN_OLECOMMAND

COleCmdUI*

CN_OLE_UNREGISTER

NULL

Ejemplo

// 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 to change
// the color of the currently selected shape) was added to the message
// map of CMyShape (note, not CMyView) using the Properties window.  
// 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)
   ON_COMMAND(ID_SHAPE_COLOR, &CMyShape::OnShapeColor)
END_MESSAGE_MAP()

Requisitos

encabezado: afxwin.h

Vea también

Referencia

Clase de CCmdTarget

Gráfico de jerarquía

Clase de CCmdUI

Clase de COleCmdUI