Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


Practical Learning: Creating a Map of Messages



  1. Create a new and empty Win32 Project located in C:\Programs\MSVC Exercises and
    set its the Name to Messages1

  2. Specify that you want to Use MFC in a Shared DLL

  3. Create a C++ file and name it Exercise

  4. 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;


  1. Test the application and return to MSVC


4.2 Windows Messages......................................................................................

Free download pdf