Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
// cs.style &= ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX);
cs.cx = 450; // Change the width
cs.cy = 350; // Change the height

return CFrameWnd::PreCreateWindow(cs);
}


  1. Test the application and return to MSVC


5.3.4 SDI Improvements: The View...........................................................


As mentioned already, the object that holds a file's data is the document which is an
object of CDocument type. To make this document available to the user to view it, in
your view derived class, you should declare a pointer to the document class. The syntax
used is:

CDocument* GetDocument() const;

When implementing this method, simply ask the application to return a pointer to the
document class used in your application. This can be done by casting the global
m_pDocument variable to your document class:

CExerciseDoc* CExerciseView::GetDocument()
{
return (CExerciseDoc*)m_pDocument;
}

You can use this GetDocument() method in your view class to access the document. For
example, the view class can access the contents of the class

If you want to allow the user to print a document, you can add a menu item identified as
ID_FILE_PRINT. Then, in the message table of the view class, use the ON_COMMAND
macro to associate it to the view parent class of your derived class. You can use this same
approach to allow the user to preview document. The identifier for this action is called
ID_FILE_PRINT_PREVIEW.

5.4 The Multiple Document Interface (MDI).................................................


5.4.1 Overview...............................................................................................


An application is referred to as Multiple Document Interface, or MDI, if the user can
open more than one document in the application without closing it. to provide this
functionality, the application provides a parent frame that acts as the main frame of the
computer program. Inside of this frame, the application allows creating views that each
uses its own frame, making it distinct from the other. Here is Microsoft Word 97
displaying as a classic MDI application:
Free download pdf