现在维护的一个软件还是用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;
}

MFC message routine的更多相关文章

  1. Meandering Through the Maze of MFC Message and Command Routing MFC消息路由机制分析

    Meandering Through the Maze of MFC Message and Command Routing Paul DiLascia Paul DiLascia is a free ...

  2. BEGIN_TEMPLATE_MESSAGE_MAP

    最近转做服务端开发,或多或少有点坑爹的感觉.目前正在恶补Linux C/C++编程,主要还是集中在Linux系统API的学习.不过也好,以后更新的内容不仅仅只有Windows了. 今天说一点简单的东西 ...

  3. windows消息处理(强烈推荐,收藏)

    由于看了一下,比较好理解,暂时先放到这里,待有空再翻译.只是在每节后大致介绍一下讲的内容. 感觉写的比较全,无论从消息的原理还是从MFC操作上来说,值得一看,我也在此做个收藏. (一) 说明:以下首先 ...

  4. UNREFERENCED_PARAMETER

    作用:告诉编译器,已经使用了该变量,不必检测警告! 在VC编译器下,如果您用最高级别进行编译,编译器就会很苛刻地指出您的非常细小的警告.当你生命了一个变量,而没有使用时,编译器就会报警告:" ...

  5. mysql: Error Codes and Messages

    Appendix B. Error Codes and MessagesTable of Contents B.1. Server Error Codes and MessagesB.2. Clien ...

  6. Eclipse 4.2 failed to start after TEE is installed

    ---------------  VM Arguments---------------  jvm_args: -Dosgi.requiredJavaVersion=1.6 -Dhelp.lucene ...

  7. MFC VS2005 添加Override 和 Message

    VS2005 1.Overrides OnInitDialog() 在Class View选中 这个类,然后properties中点Message 旁边的Overrides, 添加OnInitDial ...

  8. 【Windows Message】MFC 通过F5,刷新桌面

    //通过F5,刷新桌面 HWND hWndProgram = ::FindWindow( _T("Progman"), NULL); HWND hWndDefView = ::Fi ...

  9. mfc ui3

    引用:http://www.cnblogs.com/rainbowzc/archive/2010/06/02/1749872.html 本文专题讨论VC中的界面美化,适用于具有中等VC水平的读者.读者 ...

随机推荐

  1. Android开发---如何操作资源目录中的资源文件4 ---访问xml的配置资源文件的内容

    Android开发---如何操作资源目录中的资源文件4 XML,位于res/xml/,这些静态的XML文件用于保存程序的数据和结构. XmlPullParser可以用于解释xml文件 效果图: 描述: ...

  2. C#正则表达式MatchCollection类

    认识MatchCollection 类 表示通过以迭代方式将正则表达式模式应用于输入字符串所找到的成功匹配的集合. 命名空间:  System.Text.RegularExpressions 属性:C ...

  3. libusb示例

    #include <stdio.h> #include <libusb-1.0/libusb.h> #include <stdint.h> #include < ...

  4. C# 子类父类方法同名,三种处理方式

    1.重载:参数数量或者参数类型不同(overloading ):2.重写:override 关键字重写父类方法,父类的方法是virtual 或 abstract修饰的, using System; c ...

  5. divide&conquer:find max array

    package max_subarrayy;import java.lang.Math;public class max_subarrayy { private static int[] array; ...

  6. HDU 6095 17多校5 Rikka with Competition(思维简单题)

    Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...

  7. Linux命令学习之路——档案拷贝:cp

    使用权限:所有角色 使用方式:cp [ -arf ] source dest / cp [ -arf ] source... Directory 作用:把一个档案拷贝到另一个档案(档案复制),或将多个 ...

  8. angular file change

    AngularJs: How to check for changes in file input fields? <input type="file" onchange=& ...

  9. PowerDesigner15 增加Domain域

    第一步: 第二步: 点击此按钮,在弹出框中对Domain域打钩即可

  10. Codeforces 893A:Chess For Three(模拟)

    题目链接:http://codeforces.com/problemset/problem/893/A 题意 Alex,Bob,Carl三人下棋,每次只能两个人进行下棋,要求输的那个人当旁观者,然后给 ...