zoukankan      html  css  js  c++  java
  • DECLARE_MESSAGE_MAP 宏

      此宏描述的头文件位置: afxwin.h

    如果在 DECLARE_MESSAGE_MAP之后声明任何成员,则必须为其指定新的访问类型 (公共、 private或 protected)。说明:定义消息映射的声明类。 你的应用程序的每个 CCmdTarget 派生类,必须提供消息映射来处理消息。

    有关消息映射和 DECLARE_MESSAGE_MAP 宏的更多信息,请参见 消息处理和映射主题

    在类声明的末尾处使用 DECLARE_MESSAGE_MAP 宏。

    class CHelloApp:public CWinApp

    {

     // ……

     DECLARE_MESSAGE_MAP()

    };

    然后在定义这个类的成员函数的的 .cpp 文件中,使用 BEGIN_MESSAGE_MAP 宏、每一个消息处理函数的宏入口和 END_MESSAGE_MAP 宏。

     BEGIN_MESSAGE_MAP(CHelloMFCApp, CWinApp)
     //{{AFX_MSG_MAP(CHelloMFCApp)
     ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
      // NOTE - the ClassWizard will add and remove mapping macros here.
      //    DO NOT EDIT what you see in these blocks of generated code!
     //}}AFX_MSG_MAP
     // Standard file based document commands
     ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
     ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
    END_MESSAGE_MAP()


    如果在 DECLARE_MESSAGE_MAP之后声明任何成员,则必须为其指定新的访问类型 (公共、 private或 protected)。
    下面是错误的代码:(其实我也不知道为什么,官方文档给的说明,我试过删掉 private 也可以

    class CHelloMFCApp : public CWinApp
    {
    public:
     CHelloMFCApp();

    // Overrides
     // ClassWizard generated virtual function overrides
     //{{AFX_VIRTUAL(CHelloMFCApp)
     public:
     virtual BOOL InitInstance();
     //}}AFX_VIRTUAL

    // Implementation
     //{{AFX_MSG(CHelloMFCApp)
     afx_msg void OnAppAbout();
      // NOTE - the ClassWizard will add and remove member functions here.
      //    DO NOT EDIT what you see in these blocks of generated code !
     //}}AFX_MSG
     DECLARE_MESSAGE_MAP()

    private:  // 此处不能丢

    int i;
    };

     
  • 相关阅读:
    fatal error C1189: #error : WINDOWS.H already included. MFC apps must not #include <windows.h>
    cvWaitKey 如果 cvNamedWindow就不会起作用
    Java 并发基础
    简化Getter 与 Setter 的插件 Lombok
    20、状态模式
    mybatis-generator 覆盖新增XML
    Jvm 虚拟机
    18、备忘录设计模式
    16、 观察者设计模式
    08、仲载者 -中间者模式
  • 原文地址:https://www.cnblogs.com/herbertchina/p/4306815.html
Copyright © 2011-2022 走看看