MFC消息完成消息反射

<textarea cols="50" rows="15" name="code" class="cpp">BOOL CWnd::OnCommand(WPARAM wParam, LPARAM lParam) // return TRUE if command invocation was attempted { UINT nID = LOWORD(wParam); HWND hWndCtrl = (HWND)lParam; int nCode = HIWORD(wParam); // default routing for command messages (through closure table) if (hWndCtrl == NULL) { // zero IDs for normal commands are not allowed if (nID == 0) return FALSE; // make sure command has not become disabled before routing CTestCmdUI state; state.m_nID = nID; OnCmdMsg(nID, CN_UPDATE_COMMAND_UI, &amp;state, NULL); if (!state.m_bEnabled) { TRACE1("Warning: not executing disabled command %d/n", nID); return TRUE; } // menu or accelerator nCode = CN_COMMAND; } else { // control notification ASSERT(nID == 0 || ::IsWindow(hWndCtrl)); if (_afxThreadState-&gt;m_hLockoutNotifyWindow == m_hWnd) return TRUE; // locked out - ignore control notification // reflect notification to child window control if (ReflectLastMsg(hWndCtrl)) return TRUE; // eaten by child // zero IDs for normal commands are not allowed if (nID == 0) return FALSE; } #ifdef _DEBUG if (nCode &lt; 0 &amp;&amp; nCode != (int)0x8000) TRACE1("Implementation Warning: control notification = $%X./n", nCode); #endif return OnCmdMsg(nID, nCode, NULL, NULL); }</textarea>

在OnCmdMsg之前调用ReflectLastMsg完成消息反射,

ReflectLastMsg->SendChildNotifyLastMsg(PS:此时使用CWnd对象调用的)->OnChildNotify->ReflectChildNotify

ReflectChildNotify中调用

case WM_COMMAND:
  {
   // reflect the message through the message map as OCM_COMMAND
   int nCode = HIWORD(wParam);
   if (CWnd::OnCmdMsg(0, MAKELONG(nCode, WM_REFLECT_BASE+WM_COMMAND), NULL, NULL))
   {
    if (pResult != NULL)
     *pResult = 1;
    return TRUE;
   }
  }

其中nCode是一个标识,0是单击,1是双击,2是setfocus

对于wm_notify消息来说是一样的路线,完毕···

你可能感兴趣的:(UI,command,table,null,mfc,menu)