Mfc message routine.

现在维护的一个软件还是用mfc写的,最近被要加入一个功能弄得焦头烂额。主要现象就是加入的菜单的响应函数没被call到

上网搜索,在官方网站找到了不少资料

主要链接如下

https://msdn.microsoft.com/en-us/library/shfzay75.aspx

https://msdn.microsoft.com/en-us/library/2zdbzhex.aspx

 

文中介绍了一个例子

  1. The main frame window receives the command message first.

  2. The main MDI frame window gives the currently active MDI child window a chance to handle the command.

  3. The standard routing of an MDI child frame window gives its view a chance at the command before checking its own message map.

  4. The view checks its own message map first and, finding no handler, next routes the command to its associated document.

  5. The document checks its message map and finds a handler. This document member function is called and the routing stops.

 最后找到一个办法,就是重载CMainFrm的OnCmdMsg函数

但比较恶心的是需要检查menu id,否则在dialog的omcmdmsg可能会回掉会mainfrm导致循环调用爆掉

 

BOOL CMainFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
    
    
    if (CFrameWndEx::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
        return TRUE;

    if (nID == ID_VIEW_TEST)
    {
        if (aboutDlg)
        {
            if (aboutDlg->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
                return TRUE;
        }
    }

    return FALSE;
}

 

Powered by Jekyll and Theme by solid

本站总访问量