CWnd::Create
TOC
Collapse the table of content
Expand the table of content
This documentation is archived and is not being maintained.

CWnd::Create

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
);

Parameters

lpszClassName
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.
lpszWindowName
Points to a null-terminated character string that contains the window name.
dwStyle
Specifies the window style attributes. WS_POPUP cannot be used. If you wish to create a pop-up window, use CWnd::CreateEx instead.
rect
The size and position of the window, in client coordinates of pParentWnd.
pParentWnd
The parent window.
nID
The ID of the child window.
pContext
The create context of the window.

Return Value

Nonzero if successful; otherwise 0.

Remarks

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.

Example

// 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);
}

See Also

CWnd Overview | Class Members | Hierarchy Chart | CWnd::CWnd | CWnd::CreateEx

Show:
© 2016 Microsoft