Windows Programming with the Microsoft Foundation Classes
The diagram uses dashed arrows to show how pointers are used to relate objects. These pointers enable function members of one class object to access the public data or the function members in the interface of another object.
Document Template Classes
MFC has two classes for defining document templates. For SDI applications, the MFC library class CSingleDocTemplate is used. This is relatively straightforward because an SDI application has only one document and usually just one view. MDI applications are rather more complicated. They have multiple documents active at one time, so a different class, CMultiDocTemplate, is needed to define the document template. You’ll see more of these classes as we progress into developing application code.
Your Application and MFC
Figure 12-3 shows the four basic classes that are going to appear in virtually all your MFC-based Windows applications:
The application class CMyApp
The frame window class CMyWnd
The view class CMyView, which defines how data contained in CMyDoc is to be displayed in the client area of a window created by a CMyWnd object
The document class CMyDoc defining a document to contain the application data
The actual names for these classes are specific to a particular application, but the derivation from MFC is much the same, although there can be alternative base classes, particularly with the view class. As you’ll see a bit later, MFC provides several variations of the view class that provide a lot of functionality prepackaged for you, saving you lots of coding. You normally don’t need to extend the class that defines a document template for your application, so the standard MFC class CSingleDocTemplate usually suffices in an SDI program. When you’re creating an MDI program, your document template class is
CMultiDocTemplate, which is also derived from CDocTemplate.
The arrows in the diagram point from a base class to a derived class. The MFC library classes shown here form quite a complex inheritance structure, but in fact these are just a very small part of the complete MFC structure. You need not be concerned about the details of the complete MFC hierarchy in the main, but it is important to have a general appreciation of it if you want to understand what the inherited members of your classes are. You will not see any of the definitions of the base classes in your program, but the inherited members of a derived class in your program are accumulated from the direct base class, as well as from each of the indirect base classes in the MFC hierarchy. To determine what members one of your program’s classes has, you therefore need to know from which classes it inherits. After you know that, you can look up its members using the Help facility.
Another point you don’t need to worry about is remembering which classes you need to have in your program and what base classes to use in their definition. As you’ll see next, all of this is taken care of for you by Visual C++ 2005.