Chapter 5: The Document/View Architecture Visual C++ and MFC Fundamentals
Practical Learning: Creating a Map of Messages
- Create a new and empty Win32 Project located in C:\Programs\MSVC Exercises and
set its the Name to Messages1 - Specify that you want to Use MFC in a Shared DLL
- Create a C++ file and name it Exercise
- To create a frame for the window, in the Exercise.cpp file, type the following:
#include <afxwin.h>
class CMainFrame : public CFrameWnd
{
public:
CMainFrame ();
protected:
DECLARE_MESSAGE_MAP()
};
CMainFrame::CMainFrame()
{
// Create the window's frame
Create(NULL, "Windows Application", WS_OVERLAPPEDWINDOW,
CRect(120, 100, 700, 480), NULL);
}
class CExerciseApp: public CWinApp
{
public:
BOOL InitInstance();
};
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
END_MESSAGE_MAP()
BOOL CExerciseApp::InitInstance()
{
m_pMainWnd = new CMainFrame ;
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
CExerciseApp theApp;
- Test the application and return to MSVC