Visual C++ and MFC Fundamentals Chapter 12: Dialog-Based Windows
The second option used to add a control to an application consists of programmatically
creating it. To do this, you can call either the CreateWindow() or the
CreateWindowEx() functions.
All visible controls of the MFC library are based on the CWnd class. This class is
equipped with all the primary functionality that a regular window object needs. As the
parent of all visible window classes, it provides the other controls with properties and
methods to implement their appearance and behavior. To use the CWnd class you have
various options:
?? You can directly derive a class from CWnd
?? You can use one of the CWnd-derived classes (CView, CFrameWnd, etc)
?? You can derive a class from one of the CWnd-derived classes; for example you
can create a class based on CStatic
?? You can directly declare a CWnd variable in your application and initialize it
with the class of your choice
To create a control using a known class, you must declare a variable of the class on which
the control is based. Every control is based on a specific class, and that class is directly or
indirectly derived from CWnd. An example of such a declaration would be:
void CParentLoader::TodaysMainEvent()
{
CStatic Label;
}
You can also declare the variable as a pointer. In this case, make sure that you initialize
the class using the new operator. An example would:
void CParentLoader::TodaysMainEvent()
{
CStatic *Label = new CStatic;