This documentation is archived and is not being maintained.


Creates a Windows child window and attaches it to the CWnd object.

virtual BOOL Create(
   LPCTSTR lpszClassName,
   LPCTSTR lpszWindowName,
   DWORD dwStyle,
   const RECT& rect,
   CWnd* pParentWnd,
   UINT nID,
   CCreateContext* pContext = NULL



Points to a null-terminated character string that names the Windows class (a WNDCLASS structure). The class name can be any name registered with the global AfxRegisterWndClass function or any of the predefined control-class names. If NULL, uses the default CWnd attributes.


Points to a null-terminated character string that contains the window name.


Specifies the window style attributes. WS_POPUP cannot be used. If you wish to create a pop-up window, use CWnd::CreateEx instead.


The size and position of the window, in client coordinates of pParentWnd.


The parent window.


The ID of the child window.


Pointer to an optional CCreateContext structure used to override portions of the creation process.

Nonzero if successful; otherwise 0.

You construct a child window in two steps. First, call the constructor, which constructs the CWnd object. Then call Create, which creates the Windows child window and attaches it to CWnd. Create initializes the window's class name and window name and registers values for its style, parent, and ID.

For a list of the predefined control-class names available for the lpszClassName parameter, refer to About Window Classes.

// Dynamically create static control using CWnd::Create,
// instead of with CStatic::Create, which doesn't
// need the "STATIC" class name.

void CMyDlg::OnCreateStatic() 
   CWnd* pWnd = new CWnd;
   pWnd->Create(_T("STATIC"), "Hi", WS_CHILD | WS_VISIBLE,
       CRect(0, 0, 20, 20), this, 1234);