Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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



  1. Create the menu items as follows:

  2. (If you are using MSVC 5 or 6, first close both the menu and the icon windows. You
    will be asked to save the resource script and accept to save it. Save it as DocView.
    Then, on the main menu, click Project -> Add To Project -> Files... Select the
    DocView.rc file and click OK.

  3. Add a new header file named Exercise and, in it, create the necessary classes as
    follows:


#include <afxext.h> // For CEditView
#include "resource.h"

class CExerciseApp : public CWinApp
{
BOOL InitInstance();

DECLARE_MESSAGE_MAP()
};

class CMainFrame : public CFrameWnd
{
DECLARE_DYNCREATE(CMainFrame)

afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
DECLARE_MESSAGE_MAP()
};

class CExerciseDoc : public CDocument
{
DECLARE_DYNCREATE(CExerciseDoc)

DECLARE_MESSAGE_MAP()
};

class CExerciseView : public CEditView
{
DECLARE_DYNCREATE(CExerciseView)

DECLARE_MESSAGE_MAP()
};


  1. Add a new source file named Exercise and, in it, implement the classes as follows:


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

BEGIN_MESSAGE_MAP(CExerciseApp, CWinApp)

END_MESSAGE_MAP()

BOOL CExerciseApp::InitInstance()
{
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
Free download pdf