CCmdTarget::OnCmdMsg

Chiamato dal framework di destinazione e inviare messaggi di comando e per gestire l'aggiornamento degli oggetti dell'interfaccia utente del comando.

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

Parametri

  • nID
    Contenente l'id di comando

  • nCode
    Identifica il codice della notifica di comando.Vedere Note per ulteriori informazioni sui valori per nCode.

  • pExtra
    Utilizzato in base al valore nCode.Vedere Note per ulteriori informazioni su pExtra.

  • pHandlerInfo
    Se non NULL, OnCmdMsg inserisce i membri pmf e pTarget della struttura pHandlerInfo anziché inviare il comando.In genere, questo parametro deve essere NULL.

Valore restituito

Diverso da zero se il messaggio è gestito; in caso contrario 0.

Note

Si tratta della routine principale di implementazione dell'architettura del framework.

In fase di esecuzione, OnCmdMsg invia un comando agli altri oggetti o gestisce il comando stesso chiamando la classe radice CCmdTarget::OnCmdMsg, che esegua la ricerca effettiva della mappa messaggi.Per una descrizione completa del routing dei comandi predefinito, vedere Argomenti di mapping e di gestione dei messaggi.

In rare occasioni, è possibile eseguire l'override della funzione membro per estendere il routing di comandi standard del framework.Fare riferimento a nota tecnica 21 per i dettagli avanzati dell'architettura di routing dei comandi.

Se si esegue l'override OnCmdMsg, il valore appropriato per nCode, il codice della notifica di comando e pExtra, che dipende dal valore nCode.Nella tabella seguente sono elencati i valori corrispondenti:

Valore nCode

Valore pExtra

CN_COMMAND

CCmdUI*

CN_EVENT

AFX_EVENT*

CN_UPDATE_COMMAND_UI

CCmdUI*

CN_OLECOMMAND

COleCmdUI*

CN_OLE_UNREGISTER

NULL

Esempio

// 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()

Requisiti

Header: afxwin.h

Vedere anche

Riferimenti

Classe di CCmdTarget

Grafico della gerarchia

Classe di CCmdUI

Classe di COleCmdUI