The Simplest Document-View Application

Suppose you don't need multiple views of your document but you plan to take advantage of the application framework's file support. In this case, you can forget about the UpdateAllViews and OnUpdate functions. Simply follow these steps when you develop the application:

  1. In your derived document class header file (generated by AppWizard), declare your document's data members. These data members are the primary data storage for your application. You can make these data members public, or you can declare the derived view class a friend of the document class.

  2. In your derived view class, override the OnInitialUpdate virtual member function. The application framework calls this function after the document data has been initialized or read from disk. (Chapter 17 discusses disk file I/O.) OnInitialUpdate should update the view to reflect the current document data.

  3. In your derived view class, let your window message handlers, command message handlers and your OnDraw function read and update the document data members directly, using GetDocument to access the document object.

The sequence of events for this simplified document-view environment is as follows.

Application starts CMyDocument object constructed

CMyView object constructed

View window created

CMyView::OnCreate called (if mapped)

CMyDocument::OnNewDocument called

CMyView::OnInitialUpdate called

View object initialized

View window invalidated

CMyView::OnDraw called

User edits data CMyView functions update CMyDocument data members
User exits application CMyView object destroyed

CMyDocument object destroyed



Programming Microsoft Visual C++
Programming Microsoft Visual C++
ISBN: 1572318570
EAN: 2147483647
Year: 1997
Pages: 332

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net