C++ > CLI:バージョン情報ダイアログ

バージョン情報ダイアログです。
これまでやってきた事を組み合わせれば
これくらいは簡単にできますね。

MyForm.cpp

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

using namespace Project1;
using namespace System;
using namespace System::Reflection;
[assembly:AssemblyVersionAttribute("1.0.1.0")];

[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: ここにコンストラクター コードを追加します
   //
  }

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


 protected:

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

#pragma region Windows Form Designer generated code
  /// <summary>
  /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
  /// コード エディターで変更しないでください。
  /// </summary>
  void InitializeComponent(void)
  {
   this->button1 = (gcnew System::Windows::Forms::Button());
   this->SuspendLayout();
   //
   // button1
   //
   this->button1->Location = System::Drawing::Point(73, 95);
   this->button1->Name = L"button1";
   this->button1->Size = System::Drawing::Size(135, 23);
   this->button1->TabIndex = 0;
   this->button1->Text = L"バージョン情報";
   this->button1->UseVisualStyleBackColor = true;
   this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
   //
   // MyForm
   //
   this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
   this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
   this->ClientSize = System::Drawing::Size(284, 261);
   this->Controls->Add(this->button1);
   this->Name = L"MyForm";
   this->Text = L"Hello C++/CLI World !!";
   this->ResumeLayout(false);

  }
#pragma endregion

 private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
     version ^ver =gcnew version;
     ver->ShowDialog();
    }
 };
}
 

version.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>
 /// version の概要
 /// </summary>
 public ref class version : public System::Windows::Forms::Form
 {
 public:
  version(void)
  {
   InitializeComponent();
   //
   //TODO: ここにコンストラクター コードを追加します
   //
   // アセンブリ情報を取得
   System::Reflection::AssemblyName^ assemblyName =
    System::Reflection::Assembly::GetExecutingAssembly()->GetName();

   // プログラムのバージョンを文字列化
   String^ productVersion =
    assemblyName->Version->Major + "." +  // メジャーバージョン
    assemblyName->Version->Minor + "." +  // マイナーバージョン
    assemblyName->Version->Build;         // ビルド番号
   label1->Text = "Project " + productVersion;
  }

 protected:
  /// <summary>
  /// 使用中のリソースをすべてクリーンアップします。
  /// </summary>
  ~version()
  {
   if (components)
   {
    delete components;
   }
  }
 private: System::Windows::Forms::Button^  button1;
 protected:
 private: System::Windows::Forms::PictureBox^  pictureBox1;
 private: System::Windows::Forms::Label^  label1;
 private: System::Windows::Forms::Label^  label2;
 private: System::Windows::Forms::LinkLabel^  linkLabel1;

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

#pragma region Windows Form Designer generated code
  /// <summary>
  /// デザイナー サポートに必要なメソッドです。このメソッドの内容を
  /// コード エディターで変更しないでください。
  /// </summary>
  void InitializeComponent(void)
  {
   System::ComponentModel::ComponentResourceManager^  resources = (gcnew System::ComponentModel::ComponentResourceManager(version::typeid));
   this->button1 = (gcnew System::Windows::Forms::Button());
   this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
   this->label1 = (gcnew System::Windows::Forms::Label());
   this->label2 = (gcnew System::Windows::Forms::Label());
   this->linkLabel1 = (gcnew System::Windows::Forms::LinkLabel());
   (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->BeginInit();
   this->SuspendLayout();
   //
   // button1
   //
   this->button1->Location = System::Drawing::Point(110, 154);
   this->button1->Name = L"button1";
   this->button1->Size = System::Drawing::Size(75, 23);
   this->button1->TabIndex = 0;
   this->button1->Text = L"OK";
   this->button1->UseVisualStyleBackColor = true;
   this->button1->Click += gcnew System::EventHandler(this, &version::button1_Click);
   //
   // pictureBox1
   //
   this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^  >(resources->GetObject(L"pictureBox1.Image")));
   this->pictureBox1->Location = System::Drawing::Point(23, 21);
   this->pictureBox1->Name = L"pictureBox1";
   this->pictureBox1->Size = System::Drawing::Size(64, 64);
   this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::StretchImage;
   this->pictureBox1->TabIndex = 1;
   this->pictureBox1->TabStop = false;
   //
   // label1
   //
   this->label1->AutoSize = true;
   this->label1->Location = System::Drawing::Point(138, 43);
   this->label1->Name = L"label1";
   this->label1->Size = System::Drawing::Size(35, 12);
   this->label1->TabIndex = 2;
   this->label1->Text = L"label1";
   //
   // label2
   //
   this->label2->AutoSize = true;
   this->label2->Location = System::Drawing::Point(52, 97);
   this->label2->Name = L"label2";
   this->label2->Size = System::Drawing::Size(221, 12);
   this->label2->TabIndex = 3;
   this->label2->Text = L"Copyright (c) 2013 OpenGLプログラミングメモ";
   //
   // linkLabel1
   //
   this->linkLabel1->AutoSize = true;
   this->linkLabel1->Location = System::Drawing::Point(83, 124);
   this->linkLabel1->Name = L"linkLabel1";
   this->linkLabel1->Size = System::Drawing::Size(163, 12);
   this->linkLabel1->TabIndex = 4;
   this->linkLabel1->TabStop = true;
   this->linkLabel1->Text = L"http://www21.atwiki.jp/opengl/";
   this->linkLabel1->LinkClicked += gcnew System::Windows::Forms::LinkLabelLinkClickedEventHandler(this, &version::linkLabel1_LinkClicked);
   //
   // version
   //
   this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
   this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
   this->ClientSize = System::Drawing::Size(304, 201);
   this->Controls->Add(this->linkLabel1);
   this->Controls->Add(this->label2);
   this->Controls->Add(this->label1);
   this->Controls->Add(this->pictureBox1);
   this->Controls->Add(this->button1);
   this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedDialog;
   this->MaximizeBox = false;
   this->MinimizeBox = false;
   this->Name = L"version";
   this->ShowInTaskbar = false;
   this->Text = L"バージョン情報";
   (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->pictureBox1))->EndInit();
   this->ResumeLayout(false);
   this->PerformLayout();

  }
#pragma endregion
 private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
     this->Close();
    }
private: System::Void linkLabel1_LinkClicked(System::Object^  sender, System::Windows::Forms::LinkLabelLinkClickedEventArgs^  e) {
   // アクセス済とする
   linkLabel1->LinkVisited = true;
   // 既定のアプリケーションで URL を開く
   System::Diagnostics::Process::Start(linkLabel1->Text);
   }
};
}

 

 

 

 

 

 

最終更新:2013年10月12日 22:31
添付ファイル