掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
VC++/CLIのアイドル処理 (ID:67783)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
FormからIdleRunnerクラスのCounterメンバの値をとれるようにする。 ○delegateをつかう方法 public ref class IdleRunner { int counter; public: IdleRunner() : counter(0) {} System::Void OnIdle(System::Object^ sender, System::EventArgs^ e) { ++this->counter; } int GetCounter() { return this->counter; } }; [STAThreadAttribute] int main(array<System::String ^> ^args) { // コントロールが作成される前に、Windows XP ビジュアル効果を有効にします Application::EnableVisualStyles(); Application::SetCompatibleTextRenderingDefault(false); IdleRunner idle; Application::Idle += gcnew EventHandler(%idle, &IdleRunner::OnIdle); // メイン ウィンドウを作成して、実行します Form1 frm; frm.getcounter = gcnew Form1::GetCounterDelegate(%idle, &IdleRunner::GetCounter); Application::Run(%frm); return 0; } Form.h public: delegate int GetCounterDelegate(); GetCounterDelegate^ getcounter; private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { if (this->getcounter != nullptr) { MessageBox::Show(this->getcounter().ToString()); } } };
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.