CMDIChildWnd::Create

BOOLCreate(LPCTSTRlpszClassName**,LPCTSTRlpszWindowName,DWORDdwStyle=WS_CHILD|WS_VISIBLE|WS_OVERLAPPEDWINDOW,constRECT&rect=rectDefault,CMDIFrameWnd*pParentWnd=NULL,CCreateContext*pContext=NULL);**

Return Value

Nonzero if successful; otherwise 0.

Parameters

lpszClassName

Points to a null-terminated character string that names the Windows class (a structure). The class name can be any name registered with the AfxRegisterWndClass global function. Should be NULL for a standard CMDIChildWnd.

lpszWindowName

Points to a null-terminated character string that represents the window name. Used as text for the title bar.

dwStyle

Specifies the window style attributes. The WS_CHILD style is required. 

rect

Contains the size and position of the window. The rectDefault value allows Windows to specify the size and position of the new CMDIChildWnd.

pParentWnd

Specifies the window’s parent. If NULL, the main application window is used.

pContext

Specifies a CCreateContext structure. This parameter can be NULL.

Remarks

Call this member function to create a Windows MDI child window and attach it to the CMDIChildWnd object.

The currently active MDI child frame window can determine the caption of the parent frame window. This feature is disabled by turning off the FWS_ADDTOTITLE style bit of the child frame window.

The framework calls this member function in response to a user command to create a child window, and the framework uses the pContext parameter to properly connect the child window to the application. When you call Create, pContext can be NULL.

Example

// Example 1:
// CMainFrame::OnFileNewCMdiChildWnd() is a menu command handler for the
// CMainFrame class, which in turn is a CMDIFrameWnd-derived class.
// It shows the creation of a standard Windows MDI child window using
// the registered CMDIChildWnd class. 
void CMainFrame::OnFileNewCMdiChildWnd()
{
   CMDIChildWnd* pMDIChildWnd = new CMDIChildWnd;
   VERIFY(pMDIChildWnd->Create(
      NULL,                                        // standard CMDIChildWnd class
      _T("My MDIChildWnd"),                        // caption of MDI child window
      WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW, // window styles
      rectDefault,                                 // default rectangle size
      this));                                      // parent window; can be NULL

   // the default PostNcDestroy handler will delete this object when destroyed
}

// Example 2:
// CMainFrame::OnHello() is a menu command handler for the CMainFrame
// class, which in turn is a CMDIFrameWnd-derived class.
// It shows the creation of a Windows MDI child window using a custom
// window class. The custom window class is registered in
// CHelloWnd::Create(). CHelloWnd is a CMDIChildWnd-derived class.
void CMainFrame::OnHello()
{
   CHelloWnd *pHelloWnd = new CHelloWnd;
   if (!pHelloWnd->Create(_T("Hello"),
      WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW,
      rectDefault, this))
      return;

   // the default PostNcDestroy handler will delete this object when destroyed
}

BOOL CHelloWnd::Create(
   LPCTSTR szTitle,
   LONG style              /* = 0 */,
   const RECT& rect        /* = rectDefault */,
   CMDIFrameWnd* parent    /* = NULL */)
{
   // Setup the shared menu
   if (menu.m_hMenu == NULL)
      menu.LoadMenu(IDR_HELLO);
   m_hMenuShared = menu.m_hMenu;

   // Register a custom WndClass and create a window.
   // This must be done because CHelloWnd has a custom icon.
   LPCTSTR lpszHelloClass =
      AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW,
      LoadCursor(NULL, IDC_ARROW),
      (HBRUSH) (COLOR_WINDOW+1),
      LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_HELLO)));

   return CMDIChildWnd::Create(lpszHelloClass, szTitle, style, rect, parent);
}

CMDIChildWnd OverviewClass MembersHierarchy Chart

See Also   CMDIChildWnd::CMDIChildWnd, CWnd::PreCreateWindow