Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


The third argument, pFrameClass, if the frame class you derived from either
CFrameWnd or one of its children.

The pViewClass argument can be an MFC CView-derived class. It can also be a class
you created based on CView.

Each of these arguments must be passed as a pointer to CRuntimeClass. This can be
taken care of by using the RUNTIME_CLASS macro. Its syntax is:

RUNTIME_CLASS(ClassName);

Each one of the classes you want to use must be provided as the ClassName argument.
The RUNTIME_CLASS macro in turn returns a pointer to CRuntimeClass. To
effectively use the RUNTIME_CLASS macro, you should make sure that the (each)
class is created and implemented using the DECLARE_DYNAMIC, the
DECLARE_DYNCREATE, or the DECLARE_SERIAL macros.

To actually create the application so it can be displayed to the user, the CWinApp class is
equipped with the AddDocTemplate() method. Therefore, After creating a template, pass
the CSingleDocTemplate pointer to the CWinApp::AddDocTemplate() method. Its
syntax is:

void AddDocTemplate(CDocTemplate *pTemplate);

Everything else is subject to how you want your application to provide a useful
experience to the user.

Practical Learning: Creating a Document/View Application



  1. If necessary, start Microsoft Visual Studio or Visual C++

  2. Create a new empty Win32 application named DocView1


Figure 51: New Project - DocView1........................................................................................



  1. Click OK

  2. Specify that you want to create an empty document:

Free download pdf