1 / 24

CITA 342 Section 5

CITA 342 Section 5. Document/View Architecture. Documents and Views. The MFC document/view architecture separates a program’s data from the way that data is displayed and accessed by users. Documents and Views.

dewalt
Download Presentation

CITA 342 Section 5

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CITA 342 Section 5 Document/View Architecture

  2. Documents and Views • The MFC document/view architecture separates a program’s data from the way that data is displayed and accessed by users.

  3. Documents and Views • A program’s data (the document) is managed and stored by a class derived from the CDocument class. • How a document-based program’s data is displayed to the user is controlled by one or more classes derived from the CView class.

  4. Documents and Views

  5. Documents and Views • The following figure illustrates the concept of multiple CView classes that display and manipulate the data contained in a single CDocument class

  6. Documents and Views

  7. Document Interfaces • The single document interface, or SDI, allows users to have only one document open at a time. • The multiple document interface, or MDI, allows users to have multiple documents open at the same time. • The Multiple top-level document interface, allows user to have multiple individual SDI instances as a single instance of an MDI Application.

  8. SDI Example: Notepad

  9. MDI Example: Word 97

  10. Multiple Top-level Documents Interface Example: Word 2000+

  11. CView • You display a window created from a class derived from CView within a frame window. • This means the CView window is a child of a frame window. • The CView window completely covers the frame window’s client area, but does not cover visual interface elements such as the title bar or scroll bars.

  12. Frame Window and View Window

  13. CView Child Classes • The classes that derive from CView are used for creating more specialized view windows:

  14. CView Member Functions • A view class is responsible for graphically displaying a document’s data and for handling the manipulation of that data according to user requests. • The CView class contains various functions for displaying and manipulating data. • The primary CView class member functions that you use to display and manipulate data are as follows: • OnDraw() • GetDocument() • OnUpdate()

  15. CView::GetDocument() • The GetDocument() function returns a pointer to the document associated with a view. • The GetDocument() function returns a pointer to the m_pDocument data member that you can use anywhere in the view class when you need to access the document’s data.

  16. CView::OnUpdate() • Each view class inherits an OnUpdate() function that is called each time the document class changes or whenever the document class executes an UpdateAllViews() function. • The OnUpdate() function allows all of the view windows in an application to display the most current data.

  17. CDocument::UpdateAllViews() • The UpdateAllViews() function is a member function of CDocument and causes each view window’s OnUpdate() function to execute in order to allow each view to display the most recent data. • Passing a single value of NULL to the UpdateAllViews() function informs the system that all views in the program should be updated. • Note that you execute the UpdateAllViews() function from a derived CDocument class, not a derived CView class.

  18. CDocument • Once the MFC Application Wizard creates your derived document class, you may perform the following tasks: • Create data members to temporarily hold the data for the current document. • Override the CDocument class’s member functions to customize the creating, loading, and saving mechanisms of the document/view architecture. • Override CDocument’s Serialize() member function in order to read the document’s data from and write the document’s data to a file.

  19. CDocument Data Members • You create data members in the CDocument class by adding declarations for each data member to the interface file, the same way you create data members in other classes. • You can then initialize each data member in the class constructor and use appropriate set and get member functions to manipulate each data member. • One of the main differences between CDocument and other types of classes is that you call the set and get member functions from the view class using the GetDocument() function.

  20. CDocument Member Functions • Although many of the CDocument member functions are called automatically by the MFC framework, you can override each of the functions to customize how your application creates, loads, and saves documents.

  21. Common CDocument Member Functions

  22. CDocument Member Functions • The only functions for which the MFC Application Wizard automatically provides overridden implementations are the OnNewDocument() and Serialize() functions, because the OnNewDocument() function is one of the most commonly overridden functions and the Serialize() function is necessary for reading data from, and writing data to, files.

  23. CDocument Member Functions • When a user creates a new document in an SDI application, MFC reuses the same document object. • Because the program reuses the same document object, the values contained in the document class’s data members will appear in the fields, unless you reinitialize the data members using the DeleteContents() function.

  24. CDocument Member Functions • The SetModifiedFlag() function is used by the MFC framework to determine if a document has been modified since the last time it was saved. • When you change a document’s data, you pass to the SetModifiedFlag() function a value of TRUE to indicate that the document needs to be saved.

More Related