Share via


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 クラス WNDCLASS (構造体) を示す NULL で終わる文字列へのポインター。クラス名は AfxRegisterWndClass のグローバル関数に登録されている名前です。標準 CMDIChildWndnull が必要です。

  • lpszWindowName
    ウィンドウの名前を表す null で終わる文字列へのポインター。タイトル バーのテキストとして使用されます。

  • dwStyle
    ウィンドウの スタイル の属性を指定します。WS_CHILD のスタイルが必要です。

  • rect
    ウィンドウのサイズと位置が格納されます。rectDefault の値は、Windows が新しい CMDIChildWndのサイズと位置を指定できます。

  • pParentWnd
    ウィンドウの親を指定します。nullが、メイン アプリケーション ウィンドウが使用されます。

  • pContext
    CCreateContext の構造体を指定します。このパラメーターは nullです。

戻り値

正常終了した場合は 0 以外を返します。それ以外の場合は 0 を返します。

解説

現在アクティブな MDI 子フレーム ウィンドウは、親フレーム ウィンドウのキャプションを確認できます。子フレーム ウィンドウの機能は、この FWS_ADDTOTITLE のスタイルをオフにすると無効になります。

フレームワークは、子ウィンドウを作成するユーザー コマンドに応じてこのメンバー関数やフレームワーク使用 pContext のパラメーターをアプリケーションに正しく子ウィンドウを接続する呼び出します。**[作成]**を呼び出すと、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);
}

必要条件

ヘッダー: afxwin.h

参照

関連項目

CMDIChildWnd クラス

階層図

CMDIChildWnd::CMDIChildWnd

CWnd::PreCreateWindow