Mouse Count

Mouse Down をカウントしてタイトルバーに表示します。

前田稔(Maeda Minoru)の超初心者のプログラム入門

プログラムの説明

  1. タイトルバーを利用してデバッグに必要な情報を表示する手法は、プログラム開発において重宝します。
    今回は Mouse Down をカウントしてタイトルバーに常時表示してみましょう。
    プロジェクトの作成は 空のプロジェクトからプログラムを作成する を参照して下さい。
  2. 全ソースコードです。
    /*★ Mouse Down をカウント    前田 稔 ★*/
    #using <System.dll>
    #using <System.Windows.Forms.dll>
    #using <System.Drawing.dll>
    
    using namespace System;
    using namespace System::Windows::Forms;
    using namespace System::Drawing;
    
    ref class FormClass : public System::Windows::Forms::Form
    {
      public:
        int   cnt;
    
        //Constructor
        FormClass()
        {
            this->Text = "Bar Message";
            cnt = 0;
        }
    
        virtual void OnMouseDown(MouseEventArgs^ e) override
        {
            cnt++;
            this->Text = "cnt=" + cnt;
        }
    };
    
    //★ main() 関数
    int main()
    {
        Application::Run(gcnew FormClass());
        return 0;
    }
    
  3. 最初タイトルバー(キャプション)には "Bar Message" と表示します。
    OnMouseDown() でクリックをカウントしてタイトルバーに表示します。
            cnt++;
            this->Text = "cnt=" + cnt;
    
  4. Windows 10 でも TitleBar を使うことが出来ます。
    例題は W32 TitleBar を参照して下さい。

超初心者のプログラム入門(C/C++)