Class Derivation

Programmers often try to exploit existing code to solve new problems. In the C programming environment, the programmer can “clone” useful code by copying it and making modifications. In the C++ programming environment, you add functionality through “class derivation”. The functionality of the base class remains unmodified, but that of the derived class may be added to or changed. Derivation works well with Windows because you can extend useful window base classes with new member functions and new data members.

Suppose a frame window base class includes a caption, menu bar, scroll bars, and so forth. Also suppose that this base window has the ability to get the input focus in response to activation by the mouse. If you need to add the capability of displaying a dialog box in response to an access key, then you can derive a new class from the frame window base class. You get all the base class functionality without having to modify its code or worry about its internals.

There are three or more levels of window class derivation in a typical application built with the Microsoft Foundation classes for Windows. CWnd, the base class for all windows, contains many member functions that apply to all window types. Some second-level derived window classes, such as CFrameWnd, CMDIFrameWnd, and CMDIChildWnd, are designed for further derivation. Others, such as CDialog, can be used directly or as a base for further derivation. Finally, the classes that you derive for your own windows provide the third level of derivation.

Note:

The CWnd class is useful as a base class for SDI child windows. You do not need to derive from one of the second-level classes listed above.