Archive for 6月 5th, 2012

  1. Hello, Windows Forms(C++/CLI) World!

    Posted on 6月 5th, 2012 by cx20

    Windows Forms(C++/CLI)

    Windows フォーム(Windows Forms)は .NET Framework におけるユーザーインターフェイス基盤である。Windows アプリケーションにおけるウィンドウやダイアログに対応する。
    以下は C++/CLI における Windows フォーム の例となっている。

    ソースコード

    #using <System.dll>
    #using <System.Drawing.dll>
    #using <System.Windows.Forms.dll>
     
    using namespace System;
    using namespace System::Drawing;
    using namespace System::Windows::Forms;
     
    public ref class HelloForm : public Form
    {
    public:
        HelloForm()
        {
            this->Size = System::Drawing::Size( 640, 480 );
            this->Text = "Hello, World!";
            Label^ label1 = gcnew Label();
            label1->Text = "Hello, Windows Forms(C++/CLI) World!";
            label1->Size = System::Drawing::Size( 320, 20 );
            this->Controls->Add( label1 );
        }
    };
     
    int main( array<System::String^>^ args )
    {
       HelloForm^ form = gcnew HelloForm();
       Application::Run(form);
     
       return 0;
    }

    コンパイル方法

    C:¥> cl Hello.cpp /clr /link /SUBSYSTEM:WINDOWS /ENTRY:main

    実行結果

    +------------------------------------------+
    |Hello, World!                    [_][~][X]|
    +------------------------------------------+
    |Hello, Windows Forms(C++/CLI) World!      |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    |                                          |
    +------------------------------------------+