class CWnd : public CObject

The CWnd class provides the base functionality of all window classes in the Microsoft Foundation Class Library.

A CWnd object is actually distinct from a Windows window, but the two are tightly linked. A CWnd object is created or destroyed by the CWnd constructor and destructor. The Windows window, on the other hand, is a data structure internal to Windows that is created by the CreateEx member function and destroyed by the CWnd virtual destructor. The DestroyWindow function, one of the few public virtual CWnd member functions, destroys the Windows window without destroying the object.

The CWnd class and the message-map mechanism hide the WndProc function. Incoming Windows notification messages are automatically routed through the message map to the proper OnMessage CWnd member functions. You override the OnMessage member function to handle that member's particular message in your derived classes.

The CWnd class also provides the functionality of a Windows child window.

To create a useful child window for your application, derive a class from CWnd. Add member variables to the derived class to store data specific to your application. Implement message-handler member functions and a message map in the derived class to specify what happens when messages are directed to the window.

You create a child window in two steps. First, call the constructor CWnd to construct the CWnd object, then call the Create member function to create the child window and attach it to the CWnd object.

Construction can be a one-step process in a derived class. Write a constructor for the derived class and call Create from within the constructor.

When the user terminates your child window, destroy the CWnd object, or call the DestroyWindow member function to remove the window and destroy its data structures. If you allocate any memory in the CWnd object, override the CWnd destructor to dispose of the allocations.

Within the Microsoft Foundation Class Library, further classes are derived from CWnd to provide specific window types. Three of these classes, CFrameWnd, CMDIFrameWnd, and CMDIChildWnd, contain further window functionality and are designed for further derivation. The control classes derived from CWnd, such as CDialog and CButton, can be used directly, or can also be used for further derivation of classes.

See Also

CDialog, CModalDialog, CStatic, CButton, CEdit, CListBox, CComboBox, CScrollBar, CFrameWnd, CMDIFrameWnd, CMDIChildWnd