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;
};

 
posted @ 2014-11-24 11:13  程序员丁  阅读(1020)  评论(0编辑  收藏  举报