zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    ROS探索总结(三十一)——ros_control
    ROS探索总结(四十二)——twist_mux多路切换器
    综合面试十大维度解析
    面试官实战-2-业务面试官必须掌握的面试方法及实战演练
    面试官实战-1-素质测评起源和分析
    好的招聘官
    好的候选人
    专题工作模板
    月周报模板
    学习记录模板
  • 原文地址:https://www.cnblogs.com/cutepig/p/6576819.html
Copyright © 2011-2022 走看看