CCmdTarget::OnCmdMsg

先頭およびコマンド メッセージをディスパッチ、コマンドのユーザー インターフェイス オブジェクトの更新を処理するために、フレームワークによって呼び出されます。

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

パラメーター

  • nID
    コマンド ID が含まれています

  • nCode
    コマンド通知コードを識別します。nCodeの値に関する詳細については、[コメント] を参照してください。

  • pExtra
    nCode の値によって使用します。pExtraに関する詳細については、[コメント] を参照してください。

  • pHandlerInfo
    nullなく、OnCmdMsg がコマンドをディスパッチする代わりに pHandlerInfo の構造体の pTargetpmf のメンバーを入力します。通常、このパラメーターは null必要があります。

戻り値

メッセージが処理されたときは 0 以外を返します。それ以外の場合は 0 を返します。

解説

これは、フレームワークのコマンド アーキテクチャの主な実装のルーチンです。

実行時に、OnCmdMsg は他のオブジェクトにコマンドをディスパッチするか、実際のメッセージ マップを検索するルートのクラス CCmdTarget::OnCmdMsgを呼び出して、コマンド自体を処理します。既定のコマンド ルーティングの詳細については、トピックをメッセージの処理とマップできます。を参照してください。

ごくまれに、フレームワーク標準のコマンド ルーティングを拡張するには、このメンバー関数をオーバーライドする場合もあります。コマンド ルーティング アーキテクチャの昇格の詳細については テクニカル ノート 21 を参照してください。

OnCmdMsgをオーバーライドする場合、nCode、nCodeの値に依存するコマンド通知コードを、pExtraの適切な値を指定する必要があります。次の表は、対応する値を示します:

nCode の値

pExtra の値

CN_COMMAND

CCmdUI*

CN_EVENT

AFX_EVENT*

CN_UPDATE_COMMAND_UI

CCmdUI*

CN_OLECOMMAND

COleCmdUI*

CN_OLE_UNREGISTER

NULL

使用例

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

必要条件

ヘッダー: afxwin.h

参照

関連項目

CCmdTarget クラス

階層図

CCmdUI クラス

COleCmdUI クラス