










The message map is MFC's way of avoiding the lengthy vtables that would be required
if every class had a virtual function for every possible message it might receive.
Any class derived from CCmdTarget can contain a message map.
DECLARE_MESSAGE_MAP()
BEGIN_MESSAGE_MAP(CMyApp, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
BEGIN_MESSAGE_MAP( theClass, baseClass )
Parameters:
Specifies the name of the class whose message map this is.
Specifies the name of the base class of theClass.
MyApp.cpp
#include "stdafx.h"
Copy stdafx.h and targetver.h to the project directory.
MyApp.h
Use
#ifndef __AFXWIN_H__
#error "include 'stdafx.h' before including this file for PCH"
#endif
instead of
#include <afxwin.h>
#pragma once
#ifndef __AFXWIN_H__
#error "include 'stdafx.h' before including this file for PCH"
#endif
class CMyApp :
public CWinApp
{
public:
CMyApp();
// Overrides
public:
virtual BOOL InitInstance();
// Implementation
DECLARE_MESSAGE_MAP()
};
#include "stdafx.h"
#include "MyApp.h"
#include "MainWindow.h"
BEGIN_MESSAGE_MAP(CMyApp, CWinApp)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
CMyApp::CMyApp()
{
}
BOOL CMyApp::InitInstance()
{
m_pMainWnd = new CMainWindow();
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
CMyApp myApp;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。