CMDIChildWnd::Create

调用该成员函数创建Windows MDI子窗口并将其附加到 CMDIChildWnd 对象。

virtual BOOL Create(
   LPCTSTR lpszClassName,
   LPCTSTR lpszWindowName,
   DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_OVERLAPPEDWINDOW,
   const RECT& rect = rectDefault,
   CMDIFrameWnd* pParentWnd = NULL,
   CCreateContext* pContext = NULL 
);

参数

  • lpszClassName
    指向名为Windows选件类的Null终止的字符串( WNDCLASS 结构)。类名可以是任何名称 AfxRegisterWndClass 移到全局函数注册。应是标准 CMDIChildWndNULL

  • lpszWindowName
    指向表示窗口中的Null终止的字符串)。用作文本的标题栏。

  • dwStyle
    指定窗口 样式 属性。需要 WS_CHILD 样式。

  • rect
    包含窗口的大小和位置。rectDefault 值允许Windows指定新 CMDIChildWnd的大小和位置。

  • pParentWnd
    指定窗口的父级。如果为,则主应用程序窗口使用 NULL

  • pContext
    指定 CCreateContext 结构。此参数可以是 NULL

返回值

非零,如果成功;否则为0。

备注

当前活动的MDI子框架窗口可以确定父框架窗口的说明。此功能通过关闭 FWS_ADDTOTITLE 样式禁用bit从子框架窗口。

框架调用该成员函数以响应用户命令创建子窗口和框架使用 pContext 参数正确连接子窗口到应用程序。当您调用 Create时,pContext 可以是 NULL

示例

示例 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::OnFileNewMdiChildWnd()
{
   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
}

示例 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
   SetHandles(::LoadMenu(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_HELLO)),
      NULL);

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

要求

Header: afxwin.h

请参见

参考

CMDIChildWnd选件类

层次结构图

CMDIChildWnd::CMDIChildWnd

CWnd::PreCreateWindow