Freigeben über


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

  • [in] lpszClassName
    A null-terminated character string that contains the name of 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.

  • [in] lpszWindowName
    A null-terminated character string that contains the window name.

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

  • [in] Rect
    The size and position of the window, in client coordinates of pParentWnd.

  • [in] pParentWnd
    The parent window.

  • [in] nID
    The ID of the child window.

  • [in] pContext
    Pointer to an optional CCreateContext structure used to override portions of the creation process.

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. During this process, Create calls the function CWnd::PreCreateWindow.

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

Example

// Dynamically create static control using CWnd::Create,
// instead of with CStatic::Create, which doesn't
// need the "STATIC" class name.
void CMyDlg::OnCreateStatic() 
{
   // m_pWndStatic is a CWnd* member of CMyDlg
   m_pWndStatic = new CWnd;
   m_pWndStatic->Create(_T("STATIC"), _T("Hi"), WS_CHILD | WS_VISIBLE,
       CRect(0, 0, 20, 20), this, 1234);
}

Requirements

Header: afxwin.h

See Also

Concepts

CWnd Class

CWnd Members

Hierarchy Chart

CWnd::CWnd

CWnd::CreateEx