It should do so without imposing undue overhead on the system or unnecessarily adding to an
application's memory requirements.
The first goal was accomplished by writing classes to encapsulate windows, dialog boxes, and other objects
and by including key virtual functions that can be overridden to alter the behavior of derived classes. The
second goal required the architects of MFC to make some choices early on about how windows, menus,
and other objects would be wrapped by MFC classes such as CWnd and CMenu. Efficient use of memory
was important then and it's important today, because nobody likes a class library that produces bloated
code.
One of the ways in which the designers of MFC minimized the overhead added by the class library is
manifested in the relationship between MFC objects and Windows objects. In Windows, information about
the characteristics and current state of a window is stored in memory owned by the operating system. This
information is hidden from applications, which deal exclusively with window handles, or HWNDs. Rather
than duplicate all the information associated with an HWND in the data members of the CWnd class, MFC
wraps a window in a CWnd by storing the HWND in a public CWnd data member named m_hWnd. As a
rule, if Windows exposes an object through a handle of some type, the corresponding MFC class will
contain a data member for that handle. This knowledge can be useful if you want to call an API function
that requires a handle but you have, say, a CWnd or CWnd pointer instead of an HWND.
The Document/View Architecture
The cornerstone of MFC's application framework is the document/view architecture, which defines a
program structure that relies on document objects to hold an application's data and on view objects to
render views of that data. MFC provides the infrastructure for documents and views in the classes
CDocument and CView. CWinApp , CFrameWnd, and other classes work in conjunction with CDocument
and CView to bind all the pieces together. It's a little early to discuss the details of the document/view
architecture, but you should at least be familiar with the term document/view because it inevitably comes
up in any discussion of MFC.
The reason documents and views are so important is that document/view applications derive the greatest
benefit from the application framework. You can write MFC programs that don't use documents and views
(and we'll do a lot of that in this book, especially in Chapters 1 through 8), but to get the most out of the
framework and take advantage of some of MFC's most advanced features, you must use the
document/view architecture. That's not as restricting as it sounds, because almost any program that relies
on documents of some type can be cast in the document/view mold. Don't let the term document mislead
you into thinking that the document/view architecture is useful only for writing word processors and
spreadsheet programs. A document is simply an abstract representation of a program's data. A document
could just as easily be a byte array that stores board positions in a computerized game of chess as it could
be a spreadsheet.
What kinds of support does MFC provide to document/view applications? Among other things, the
document/view architecture vastly simplifies printing and print previewing, the mechanics of saving
documents to disk and reading them back again, and converting applications into Active document servers
whose documents can be opened in Microsoft Internet Explorer. You'll learn all about the document/view
architecture in Part II of this book, but only after you've done some programming without documents and
views so that you can get to know MFC without having too much heaped on your plate at once.
The MFC Class Hierarchy
MFC provides a variety of classes designed to serve a wide range of needs. You'll find a handy diagram of
the MFC 6.0 class hierarchy inside the front cover of this book.
The majority of MFC classes are derived, either directly or indirectly, from CObject. CObject provides
three important features to classes that inherit from it:
Serialization support
Run-time class information support
Diagnostic and debugging support
Serialization is the process of streaming an object's persistent data to or from a storage medium such as a
disk file. By using CObject as a base class, you can write serializable classes whose instances are easily
saved and re-created. Run-time class information (RTCI) lets you retrieve an object's class name and