C++ > CLI:MDI

基本プロジェクトを立ち上げます。
フォームのプロパティの IsMdiContainer を True にします。


プロジェクトに新しい項目を追加します。


Visual C++ の UI の Windowsフォームを選択し、名前を
MDIForm.h にして追加ボタンを押します。


MyForm を選択して、Size を Width 640、Height 480 にします。


MyForm.h のコードを表示して、以下のコードを追加します。

   //
   //TODO: ここにコンストラクター コードを追加します
   //
   Form^ MDIForm = gcnew Form;
   int childCount=0;
   childCount++;
   String^ formText = String::Format( "MDIForm {0}", childCount );
   MDIForm->Text = formText;
   MDIForm->MdiParent = this;
   MDIForm->Show();


ビルドして実行してみましょう。


子フォームの最大化ボタンを押すと親フォームのMDIコンテナ一杯に広がります。


子フォームの最小化ボタンを押すと親フォームのMDIコンテナの左下に隠れます。

MyForm.cpp

#pragma comment(linker, "/SUBSYSTEM:WINDOWS /ENTRY:mainCRTStartup")
#include "MyForm.h"

using namespace Project1;

[STAThreadAttribute]
int main(){
 MyForm ^form1 = gcnew MyForm;
 form1->ShowDialog();
 return 0;
}

MyForm.h

#pragma once

namespace Project1 {

 using namespace System;
 using namespace System::ComponentModel;
 using namespace System::Collections;
 using namespace System::Windows::Forms;
 using namespace System::Data;
 using namespace System::Drawing;

 /// <summary>
 /// MyForm の概要
 /// </summary>
 public ref class MyForm : public System::Windows::Forms::Form
 {
 public:
  MyForm(void)
  {
   InitializeComponent();
   //
   //TODO: ここにコンストラクター コードを追加します
   //
   Form^ MDIForm = gcnew Form;
   int childCount=0;
   childCount++;
   String^ formText = String::Format( "MDIForm {0}", childCount );
   MDIForm->Text = formText;
   MDIForm->MdiParent = this;
   MDIForm->Show();
  }

 protected:
  /// <summary>
  /// 使用中のリソースをすべてクリーンアップします。
  /// </summary>
  ~MyForm()
  {
   if (components)
   {
    delete components;
   }
  }


 protected:

 private:
  /// <summary>
  /// 必要なデザイナー変数です。
  /// </summary>
  System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
  /// <summary>
  /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
  /// コード エディターで変更しないでください。
  /// </summary>
  void InitializeComponent(void)
  {
   this->SuspendLayout();
   //
   // MyForm
   //
   this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
   this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
   this->ClientSize = System::Drawing::Size(624, 441);
   this->IsMdiContainer = true;
   this->Name = L"MyForm";
   this->Text = L"Hello C++/CLI World !!";
   this->ResumeLayout(false);

  }
#pragma endregion

 };
}

MDIForm.cpp

#include "MDIForm.h"

MDIForm.h

#pragma once

namespace Project1 {

 using namespace System;
 using namespace System::ComponentModel;
 using namespace System::Collections;
 using namespace System::Windows::Forms;
 using namespace System::Data;
 using namespace System::Drawing;

 /// <summary>
 /// MDIForm の概要
 /// </summary>
 public ref class MDIForm : public System::Windows::Forms::Form
 {
 public:
  MDIForm(void)
  {
   InitializeComponent();
   //
   //TODO: ここにコンストラクター コードを追加します
   //
  }

 protected:
  /// <summary>
  /// 使用中のリソースをすべてクリーンアップします。
  /// </summary>
  ~MDIForm()
  {
   if (components)
   {
    delete components;
   }
  }

 private:
  /// <summary>
  /// 必要なデザイナー変数です。
  /// </summary>
  System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
  /// <summary>
  /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
  /// コード エディターで変更しないでください。
  /// </summary>
  void InitializeComponent(void)
  {
   this->components = gcnew System::ComponentModel::Container();
   this->Size = System::Drawing::Size(300,300);
   this->Text = L"MDIForm";
   this->Padding = System::Windows::Forms::Padding(0);
   this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  }
#pragma endregion
 };
}

 

 

 

 

 

 

最終更新:2013年09月30日 19:40