OnCommand 与OnCmdMsg
来源:互联网 发布:淘宝助理打印 编辑:程序博客网 时间:2024/04/30 18:37
1、首先两者都是虚函数
CWnd::OnCommand,CCmdTarget::OnCmdMsg
2、看源码
- 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, &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->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 < 0 && nCode != (int)0x8000)
- TRACE1("Implementation Warning: control notification = $%X.\n",
- nCode);
- #endif
- return OnCmdMsg(nID, nCode, NULL, NULL);
- }
其中:OnCommand中调用OnCmdMsg。
- BOOL CCmdTarget::OnCmdMsg(UINT nID, int nCode, void* pExtra,
- AFX_CMDHANDLERINFO* pHandlerInfo)
- {
- <span style="WHITE-SPACE: pre"> </span>// 省略
- return FALSE; // not handled
- }
OnCmdMsg :
Called by the framework to route and dispatch command messages and to handle the update of command user-interface objects.
调用框架路由和调度命令消息和处理更新用户界面对象的命令。
The framework calls this member function when the user selects an item from a menu, when a child control sends a notification message, or when an accelerator keystroke is translated.
该框架调用该成员函数当用户选择一个项目从一个菜单,当一个孩子控制发送一个通知消息,或者当一个加速器击键是翻译。
- BOOL CToolTipDlg::OnCommand(WPARAM wParam, LPARAM lParam)
- {
- // TODO: Add your specialized code here and/or call the base class
- assert(wParam);
- switch(lParam)
- {
- case WM_RBUTTONDOWN:
- AfxGetApp()->m_pMainWnd->ShowWindow(SW_SHOW);
- break;
- }
- return CDialog::OnCommand(wParam, lParam);
- }
响应WM_COMMAND消息 做出相应 的处理
一个项目中使用的代码
BOOL CGameControl::OnCommand(WPARAM wParam, LPARAM lParam)
{
int id = LOWORD(wParam); //IDC_CONTROL_HALL+m_gameSerId.RoomID
CMainFrame *pMainFrame = theApp.GetMainFrame();
if(HIWORD(wParam)==BN_DOUBLECLICKED)
{
if(id == DLGBOTTOM_ID_ROOM) // 按键ID
{
if(m_gameSerId.RoomID>0)
pMainFrame->PostMessage(WM_GAME_CONTROL,ROOMSVR,1);
}
}
return CDialog::OnCommand(wParam, lParam);
其中相关:
- OnCommand 与OnCmdMsg
- MFC OnCommand和OnCmdMsg
- OnCmdMsg
- OnCmdMsg
- OnClick与OnCommand
- OnUpdateCmdUI 与 OnCommand 的区别
- oncommand与CommandArgument的联系
- onclick与onCommand的区别
- OnCmdMsg -- CFrameWnd::OnCmdMsg and CView::OnCmdMsg
- asp.net中OnClick与OnCommand的区别及用法
- OnCommand函数
- OnCmdMsg标准处理流程
- OnCmdMsg 处理程序
- OnCmdMsg() VS PostMessage()
- asp.net按钮 button的onclick事件 与oncommand 事件的区别
- OnCommand的解释
- OnClick和OnCommand的区别
- MFC的CFrameWnd::OnCmdMsg消息链路
- 轻松创建Silverlight 4开发环境
- windows下开发apache模块环境部署(apache,perl,apxs)
- ubuntu 目录结构
- iOS 常用的加密方法
- 【设计模式攻略】创建型模式之Abstract Factory模式
- OnCommand 与OnCmdMsg
- 转载 从linux转到vs的问题(制作FFmpeg SDK for MS Visual Studio)
- 锁存器和自旋锁(Latch&Spinlock)----监视Latch和Spinlock
- jquery的几种异步请求,ajax
- Expert Tips on Drop Temporary Tablespace Hangs!!
- Linux下PPTP的VPN拨号设置(客户端)
- 枚举类型与结构体初步
- Android 文字对齐
- Qt 平台中使GUI保持响应流畅