Dela via


CWnd::CreateEx

Creates the specified window and attaches it to the CWnd object.

virtual BOOL CreateEx(
   DWORD dwExStyle,
   LPCTSTR lpszClassName,
   LPCTSTR lpszWindowName,
   DWORD dwStyle,
   int x,
   int y,
   int nWidth,
   int nHeight,
   HWND hWndParent,
   HMENU nIDorHMenu,
   LPVOID lpParam = NULL 
);
virtual BOOL CreateEx(
   DWORD dwExStyle,
   LPCTSTR lpszClassName,
   LPCTSTR lpszWindowName,
   DWORD dwStyle,
   const RECT& rect,
   CWnd* pParentWnd,
   UINT nID,
   LPVOID lpParam = NULL
);

Parameters

  • dwExStyle
    Bitwise combination (OR) of extended window styles; otherwise NULL for the default extended window style.

  • 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.

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

  • dwStyle
    Bitwise combination (OR) of window styles; otherwise NULL for the default window style.

  • x
    The initial horizontal distance of the window from the left side of the screen or the parent window.

  • y
    The initial vertical distance of the window from the top of the screen or the parent window.

  • nWidth
    The width, in pixels, of the window.

  • nHeight
    The height, in pixels, of the window.

  • hwndParent
    For a child window, the handle to the parent window; otherwise, the handle of the owner window if the window has an owner.

  • nIDorHMenu
    For a child window, the window ID; otherwise, the ID of a menu for the window.

  • lpParam
    Pointer to user data that is passed to the CWnd::OnCreate method in the lpCreateParams field.

  • rect
    The size and location of the window relative to the screen or the parent window.

  • pParentWnd
    For a child window, pointer to the parent window; otherwise, pointer to the owner window if the window has an owner.

  • nID
    For a child window, the window ID; otherwise, the ID of a menu for the window.

Return Value

TRUE if the method was successful; otherwise FALSE.

Remarks

The default extended window style is WS_EX_LEFT. The default window style is WS_OVERLAPPED.

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

Dimensions for child windows are relative to the top-left corner of the client area of the parent window. Dimensions for top-level windows are relative to the top-left corner of the screen.

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

Example

void CMyDlg::OnCreateExtendedControl() 
{
   // m_pWndStaticEx is a CWnd* member of CMyDlg
   m_pWndStaticEx = new CStatic;
   m_pWndStaticEx->CreateEx(WS_EX_CLIENTEDGE, // Make a client edge label.
      _T("STATIC"), _T("Hi"),
      WS_CHILD | WS_TABSTOP | WS_VISIBLE,
      5, 5, 30, 30, m_hWnd, (HMENU)2345);
}

Requirements

Header: afxwin.h

See Also

Concepts

CWnd Members

Reference

CWnd Class

Hierarchy Chart

CWnd::Create

CreateWindowEx

Change History

Date

History

Reason

October 2008

Updated whole topic.

Customer feedback.