Delen via


CWnd::Create

Creates the specified 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
    Pointer to a null-terminated string that contains the name of a registered system window class; or the name of a predefined system window class.

  • [in] lpszWindowName
    Pointer to a null-terminated string that contains the window display name; otherwise NULL for no window display name.

  • [in] dwStyle
    Bitwise combination (OR) of window styles. The WS_POPUP option is not a valid style.

  • [in] rect
    The size and location of the window relative to the top-left corner of the parent window.

  • [in] pParentWnd
    Pointer to the parent window.

  • [in] nID
    ID of the window.

  • [in] pContext
    Pointer to a CCreateContext structure that is used to customize the document-view architecture for the application.

Return Value

TRUE if the method was successful; otherwise FALSE.

Remarks

Use the AfxRegisterWndClass function to register window classes. User defined window classes are available in the module where they are registered.

The CWnd::OnCreate method is called before the Create method returns, and before the window becomes visible.

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 Members

Reference

CWnd Class

Hierarchy Chart

CWnd::CWnd

CWnd::CreateEx

CreateWindowEx

Change History

Date

History

Reason

October 2008

Updated whole topic.

Customer feedback.