February 21, 2001

The MFC Class Hierarchy:

MFC (Microsoft Foundation Classes) provides a variety of classes designed to serve a wide range of needs.

The following gives you the overview of the classes present in MFC.

The root class present in MFC is CObject.
1. There are two categories of classes in MFC.
The root class for MFC is “CObject”.
The Category lies here, classes which are derived directly or indirectly from Object and classes which are not derived from CObject.
2. Most of the MFC classes are inherited from CObject class.


CObject contains
· Nine member functions (Five are virtual)
· Five Operators Overloaded functions.
· Single Data Member.

These functions of CObject supports
· Memory allocation.
· Serialization.
· Diagnostic support.
· Basic object architecture.


1. CObject

CObject’s declaration is present in AFX.H header file

Generally CObject classes provides three basic services to the class(es) that inherit from it.

Serialization support.

Serialization is the process by which objects archive themselves to and from a storage object such as a file on the disk. CObject includes two member functions

“IsSerializable()” which returns TRUE if an object is serializable and returns FALSE if an object is not serilizable.

“Serialize()” this function serilizes the object’s data members to a storage medium represented by CArchive class.

Run-time class information support.

Run-time class information support means, Given a pointer to an object of a class derived from CObject it can give details about class name, and its relation-ship between a specific class.

Eg., Functions which does runtime class information support “IsKindOf” and “GetRuntimeClass” etc.,

These functions are the classes whose object does the following:

# Creates the Class.
# Inspects the class.

RTC supports

# identification of class.
# allocation of a class.

MACROS that supports RTC are

DECLARE_DYNAMIC ----- to enable a runtime class.
DECLARE_DYNCREATE ---- to create a runtime class declaration.
IMPLEMENT_DYNAMIC ---- to generate C++ code which is necessary for the class to obtain runtime class information and its position in the hierarchy.

Diagnostic and debugging support.

This feature is to check the correctness of any operations, Eg., check whether pointer has been got from a function.

ASSERT_VALID(pDoc) -> Checks the pDoc pointer has a value.

TRACE :

This provides “printf” like capabilities in DEBUG version. There are TRACE0, TRACE1, TRACE2 & TRACE3 which will be used as printf statements.

eg.,
TRACE0 “%d”,x;
ASSERT :
ASSERT(boolean_expression)


This function evaluates the expn. and if false displays a message box during RUNTIME.

ASSERT_VALID(object_pointer)

This tests the internal validity of an object by calling it.


2. There are some classes which are not of CObject class ie., they are not inherited from CObject.

Around 22 classes of MFC which are not derived from CObject.

Ex.,
CPoint,CString etc.,

MFC has a different types of Classes under CObject :

(i) Window Classes : Base class : CWnd

These classes encapsulates the properties of a window. It provides default handlers for many messages. It has dozens of function which can perform operations on windows.
CWnd is the base class for all the window classes. It includes CFrameWnd and CMDIFrameWnd classes which has basic operations on the window. It also includes CView class which forms the foundation for the views in documents/View applications.
It also includes CDialog class which forms the base class for the dialog applications.

(ii) GDI Classes : (Graphical Device Interface) Base class : CDC

These classes are responsible for the output on the Screen,printers and other devices.
CDC is the classes for the Device Context class. CPaintDC, CWindow DC and CClientDC are the other classes derived from CDC class.

(iii) File Class : Base class : CFile
These classes provide a object oriented interface to files by taking standard file I/O functions such as READ and WRITE etc., CFile forms the base class for the other classes such as
CMemFile, CStdioFile etc.,

(iv) Exception Classes : Base Class : CException
These classes are used to handle exceptions which C++ provides try/throw/catch etc.,

CException is the base class for the exception classes,
CFileException,CMemoryException etc., are the
derived classes for the CException classes.

(v) OLE Classes :(OBJECT LINKING AND EMBEDDING)
Base class : COleDocument

These classes OLE application supports to the application developed by programmer.

COleDocument & CDocItem are the base classes for the OLE classes.

Some of the OLE classes are the COleDropSource, COleDropTarget etc., are derived from COleDocument and CDocItem.

(vi) Database Classes : Base Classes :

CDataBase
CRecordset.

These classe are to interface the VC++ program with a data base. The databases can be either dbf file or Oracle files etc., CDatabase and CRecordset are the base classes of the data base class. Other classes are CRecordView and CLongBinary are inherited from the CDatabase / CRecordset.

(vii) Threading Classes : Base Class : CWinThread

These classes encapsulates threads of execution. CWinThread is the base class for the threading class.

(viii) General purpose classes :

These classes are not derived from CObject class. They simply have data only to store the data.
Egs., CPoint CSize etc., are the general purpose classes.