最終更新: edward_black 2012年04月12日(木) 22:47:25履歴
- 新しいプロジェクトからwindowsフォームアプリケーションを選択、プロジェクト名を決定する
- ソースファイル→新しいファイル→「Form1.cpp」を追加する。この時、Form1.hをインクルードして、プロジェクト名の名前空間を使用することを記述しておく
- #include"Form1.h"
- using namespace プロジェクト名;
- Form1.h上ではプロトタイプ宣言を行い、実処理はForm1.cppに記述することで、Form1.hの可読性を良くする
- この方針でプロジェクトを作りました
- Form1.cppも一杯になってきたら、更に別のcppファイルを用意して、Form1.cppで呼ぶ形にしました
- クラスを作るとC++/CLIらしくなります
- 親フォームと子フォームを作って、データの受け渡しをする場合も、publicなクラスを作成すると便利です
- 例)ボタン(オブジェクト名:button_open)のクリック時の動作を記述する
2. ツールボックスからボタンを選択し、デザイナ上に配置
3. ボタンをダブルクリックして、Form1.hにイベントハンドラを作成
4. 作成されたコードの中括弧{}を排除して、行末に;を付けてプロトタイプ宣言にする
(private:System::Void button_open_Click(System::Object^ sender, System::EventArgs^ e);
5. Form.cppで具体的な記述
System::Void Form1::button_open_Click(System::Object^ sender, System::EventArgs^ e)
{
ボタンクリック時の処理です
}
※先にForm1.hにプロトタイプ宣言を記述して、次にcppファイルを操作すれば、System::Void Form1::とタイプした段階でインテリセンスが出てきて、その中にbutton_Click(...)が入っている。
- ボタンクリック時の処理が長くなる場合は関数化していく
- System::Void function(IplImage *input, IplImgae *output, ... ...)みたいな関数を用意
- Form1.hにプロトタイプ宣言、Form1.cppに処理を記述、button_open_Click()内で呼び出す
- 大きなプログラムの場合は、自作関数は別のファイルにまとめた方が見やすい
このページへのコメント
Great topic and well written. Do you have any more resources
about this that you reccommend?
Great topic and well written. Do you have any more resources about this that you
reccommend?
Great topic and well written. Do you have any
more resources about this that you reccommend?
Great topic and well written. Do you have any more resources about this that you reccommend?
Great topic and well written. Do you have any more resources about this that you reccommend?