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;
    }
  • 相关阅读:
    cloudera cdh4 hue 安装
    设计模式Observer(观察者模式)
    编译android源码三(编译系统)
    centos 6.3 修改默认的系统语言
    Linux下查看文件和文件夹大小的df和du命令
    编译android源码二(下载源代码)
    devenv.exe
    Javascript和xml合用
    DataKeys的用法
    XSL(转)
  • 原文地址:https://www.cnblogs.com/cutepig/p/6576819.html
Copyright © 2011-2022 走看看