- Table of Contents
- Copyright
- About the Authors
- About the Contributors
- Acknowledgments
- Tell Us What You Think!
- Introduction
- How to Use This Book
- What You Need to Use This Book
- What's New in Visual C++ 6.0
- Contacting the Main Author
- Part I: Introduction
- Chapter 1. The Visual C++ 6.0 Environment
- Part II: MFC Programming
- Chapter 2. MFC Class Library Overview
- Chapter 3. MFC Message Handling Mechanism
- Chapter 4. The Document View Architecture
- Chapter 5. Creating and Using Dialog Boxes
- Chapter 6. Working with Device Contexts and GDI Objects
- Chapter 7. Creating and Using Property Sheets
- Chapter 8. Working with the File System
- Chapter 9. Using Serialization with File and Archive Objects
- Part III: Internet Programming with MFC
- Chapter 10. MFC and the Internet Server API (ISAPI)
- Chapter 11. The WinInet API
- Chapter 12. MFC HTML Support
- Part IV: Advanced Programming Topics
- Chapter 13. Using the Standard C++ Library
- Chapter 14. Error Detection and Exception Handling Techniques
- Chapter 15. Debugging and Profiling Strategies
- Chapter 16. Multithreading
- Chapter 17. Using Scripting and Other Tools to Automate the Visual C++ IDE
- Part V: Database Programming
- Chapter 18. Creating Custom AppWizards
- Chapter 19. Database Overview
- Chapter 20. ODBC Programming
- Chapter 21. MFC Database Classes
- Chapter 22. Using OLE DB
- Chapter 23. Programming with ADO
- Part VI: MFC Support for COM and ActiveX
- Chapter 24. Overview of COM and Active Technologies
- Chapter 25. Active Documents
- Chapter 26. Active Containers
- Chapter 27. Active Servers
- Chapter 28. ActiveX Controls
- Part VII: Using the Active Template Library
- Chapter 29. ATL Architecture
- Chapter 30. Creating COM Objects Using ATL
- Chapter 31. Creating ActiveX Controls Using ATL
- Chapter 32. Using ATL to Create MTS and COM+ Components
- Part VIII: Finishing Touches
- Chapter 33. Adding Windows Help
- Part IX: Appendix
Examining the Document View Architecture
MFC not only provides a set of classes to help you work with document objects, but it provides a complete architecture that ties the various classes together. In this chapter, you will look at this architecture and what it can do for your applications. I think you will find that the whole of the architecture is much greater than the sum of its parts.
Single Versus Multiple Document Applications
If you have used Windows at all, you should be familiar with applications such as Microsoft Word that enable you to work with several documents within the same application. In Windows terms, these are known as multiple document interfaces (MDIs). In addition to the support the Windows Software Development Kit (SDK) provides for MDI, MFC encapsulates MDI in the classes that make up the document view architecture.
The single document interface (SDI) is similar to MDI but is designed for simpler applications that work with only one document and one view at any given time. Both MDI and SDI applications can use the document view architecture provided by MFC in much the same way, except the MDI architecture provides an additional level of functionality to deal with multiple documents and views.
Of course, you are not required to use the document view architecture in your applications, and you most likely will have situations in which you don't even want to have a Windows user interface. You can use MFC in your applications without any GUI interface, or you can base your application on a single dialog box. If your application fits in the document view model, however, you will find that creating your application using either the SDI or MDI flavor of the document view architecture can greatly simplify your task of adding features that Windows users have come to expect from all good Windows applications.
Document Classes
Although it doesn't take much imagination to see how a document object would apply to a word processing or spreadsheet application, the concept of a document in MFC also can apply to much more. In general terms, a document is any set of data that can be grouped logically. This data may include anything from settings for a terminal session to simulation models to information about your favorite records to just about anything else you might consider writing to a file. In MFC, document objects are derived from the CDocument class. In most cases, your application somehow will present the data in your document to the user. This is done by using views.
View Classes
A view object is just that—a view of the document. This may be either some direct representation of the document object or some other sort of display related to the data in your document. For example, your document may store settings for some data-acquisition application, and your views will show the data acquired based on those settings. As you might guess, view objects in MFC are derived from the CView class. However, you probably will derive your view classes from some of the other classes MFC provides for you that add functionality to the basic CView class.
Frames
MFC applications that use the document view architecture use frames to contain the views of the application. In SDI applications, the frame that contains the one and only view also serves as the main frame, or main window, of your application. In MDI applications, this functionality is split between the main frame, which is the main window for your application, and child frames, which provide windows in which each of your views can run. The frame objects handle the menus, status bars, and toolbars for your application. The frame objects also receive the command messages generated in your views. In SDI applications, frame windows are derived directly from the CFrameWnd class, and MDI main frames and child frames are derived from CMDIFrameWnd and CMDIChildWnd, respectively.
Document Templates
MFC uses document templates to tie your documents, views, and frames together. As you will see, it is actually the document template that creates new documents and new view windows to display them. Document templates are derived from class CSingleDocTemplate for SDI apps and from class CMultiDocTemplate for MDI apps.
Creating Your Application | Next Section

Account Sign In
View your cart