1

フォームのピクチャ ボックスに WndProc 関数を使用するにはどうすればよいですか? 私はこのコードのように試してみましたが、機能せず、パブリックにメッセージが送信されません: virtual void WndProc( Message% m )

using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
namespace MyProject {
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void) {
            InitializeComponent();
            //TODO: Add the constructor code here
        }
    protected:
        ~Form1() {
            if (components)
                delete components;
        }
    private:
        System::Windows::Forms::PictureBox^  pictureBox1;
        System::ComponentModel::Container ^components;

        void InitializeComponent(void) {
            this->pictureBox1 = gcnew System::Windows::Forms::PictureBox();
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(
                this->pictureBox1))->BeginInit();
            this->SuspendLayout();
            // 
            // pictureBox1
            // 
            this->pictureBox1->Location = System::Drawing::Point(41, 27);
            this->pictureBox1->Name = L"pictureBox1";
            this->pictureBox1->Size = System::Drawing::Size(206, 203);
            this->pictureBox1->TabIndex = 0;
            this->pictureBox1->TabStop = false;
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(292, 265);
            this->Controls->Add(this->pictureBox1);
            this->Name = L"Form1";
            this->Text = L"Form1";
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(
                this->pictureBox1))->EndInit();
            this->ResumeLayout(false);
        }
    };

    ref class pictureBox1 : PictureBox {
    public:
        virtual void WndProc( Message% m ) override {
            __super::WndProc(m);
        }
    };
}//close NameSpace
4

2 に答える 2

2

新しいクラスを作成しましたが、それを使用したことはありません。
ピクチャボックスを新しいクラスのインスタンスに変更する必要があります。

ただし、しないでください。

WndProcどうしても必要な場合を除き、.Net 開発では使用しないでください。ここでは必要ありません。
.Net イベントを使用する必要があります。

于 2011-01-26T14:09:21.177 に答える
1

SLaks が提供した答えは正しいです。スタック オーバーフローから魔法のスニペットをコピーして貼り付けるのではなく、コードの意味を理解する必要があるという彼のコメントに 100% 同意します。

しかし、組み込みのクラスではなく、カスタムPictureBoxクラス (関数をオーバーライドしたクラス)を使用するコードをどのように記述すべきかについて、あなたはまだ悲鳴を上げているようです。これは、 (カスタム クラス)へWndProcのすべての参照を変更するという単純な問題です。もちろん、いずれかの名前を変更する必要がありますが、すべてのデフォルトよりも適切な名前を選択することをお勧めします。System::Windows::Forms::PictureBoxpictureBox1

たとえば、次のことを試してください。

namespace MyProject {

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;


    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

    protected:

        ~Form1()
        {
            if (components)
            {
                delete components;
            }
        }
    private: pictureBox1^ myPictureBox;
    protected: 

    private:

        System::ComponentModel::Container ^components;


        void InitializeComponent(void)
        {
            this->myPictureBox = (gcnew pictureBox1());
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->myPictureBox))->BeginInit();
            this->SuspendLayout();
            // 
            // myPictureBox
            // 
            this->myPictureBox->Location = System::Drawing::Point(41, 27);
            this->myPictureBox->Name = L"myPictureBox";
            this->myPictureBox->Size = System::Drawing::Size(206, 203);
            this->myPictureBox->TabIndex = 0;
            this->myPictureBox->TabStop = false;
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(292, 265);
            this->Controls->Add(this->myPictureBox);
            this->Name = L"Form1";
            this->Text = L"Form1";
            (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->myPictureBox))->EndInit();
            this->ResumeLayout(false);

        }

    };




ref class pictureBox1  : PictureBox  {
    //protected:
    public:      
        virtual void WndProc( Message% m ) override {
                        __super::WndProc(m);
        }
    };




}//close NameSpace
于 2011-01-26T15:17:16.523 に答える