Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 5: The Document/View Architecture


To implement the messages, you should/must create a table of messages that your
program is using. This table uses two delimiting macros. Its starts with a
BEGIN_MESSAGE_MAP and ends with an END_MESSAGE_MAP macros. The
BEGIN_MESSAGE_MAP macro takes two arguments, the name of your class and the
MFC class you derived your class from. An example would be:

BEGIN_MESSAGE_MAP(CSimpleFrame, CFrameWnd)

Like the DECLARE_MESSAGE_MAP macro, END_MESSAGE_MAP takes no
argument. Its job is simple to specify the end of the list of messages. The table of
messages can be created as follows:

#include <afxwin.h>
#include "resource.h"

class CMainFrame : public CFrameWnd
{
public:
CMainFrame ();

DECLARE_MESSAGE_MAP()
};

CMainFrame::CMainFrame()
{
LoadFrame(IDR_MAINFRAME);
}

class CMainApp: public CWinApp
{
public:
BOOL InitInstance();
};

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)

END_MESSAGE_MAP()

BOOL CMainApp::InitInstance()
{
m_pMainWnd = new CMainFrame ;
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();

return TRUE;
}

CMainApp theApp;

There various categories of messages the operating system receives. Some of them come
from the keyboard, some from the mouse, and some others from various other origins.
For example, some messages are sent by the application itself while some other messages
are controlled by the operating.
Free download pdf