C++/CLIでのフォーム
OpenCVをDLL,表示部をC#と二つに分けていたが
単体で完結した方が開発しやすい気がした。
んなことでC++/CLIを試してみた。ほとんどC#みたいだけど細部が微妙に違うのがねー
コード
#include <stdio.h> #include <windows.h> #using <System.dll> #using <System.Drawing.dll> #using <System.Windows.Forms.dll> using namespace System; using namespace System::Drawing; using namespace System::Windows::Forms; // コマンドプロンプトを表示させない //#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"") //フォームを作成するクラス ref class FormClass : System::Windows::Forms::Form { private: public: // コンストラクタ FormClass() { this->Text = "CLIテスト"; // タイトル this->BackColor = Color::LightBlue; // 背景色 this->Paint += gcnew PaintEventHandler(MyHandler); // 描画イベント関連付け } // イベントハンドラ static void MyHandler(Object^ sender, PaintEventArgs^ e){ Graphics^ g = e->Graphics; g->DrawLine(gcnew Pen(Color::Red, 1), 10, 150, 260, 150); } // マウスクリックイベントをオーバライド virtual void OnMouseClick(MouseEventArgs^ e) override{ Application::Exit(); // 終了 } }; // Main関数 [STAThreadAttribute] int main() { Application::Run(gcnew FormClass()); return 0; }