如何使用WndProc?
如何在我的表单中使用 WndProc 函数作为图片框? 我像这段代码一样尝试,但它不起作用,并且没有任何消息发送到我的 public: virtual void WndProc(消息%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
How to use WndProc Funection for a picturebox in my form ?
i try it like this code but it not work and not any message send to my
public: 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
SLAks 提供的答案是正确的,我 100% 同意他的评论,即您需要理解代码的含义,而不是从 Stack Overflow 复制并粘贴神奇的片段。
但我发现您仍然在尖叫如何编写代码来使用自定义
PictureBox
类(您覆盖了WndProc
函数的类),而不是内置一个。这实际上是一个简单的问题,将对System::Windows::Forms::PictureBox
的所有引用更改为pictureBox1
(您的自定义类)。当然,您需要更改其中一个名称,但我建议为所有内容选择比默认名称更好的名称。例如,尝试以下操作:
The answer provided by SLaks is correct, and I agree 100% with his comments that you need to understand what the code means, rather than copying and pasting a magical snippet off Stack Overflow.
But I see you're still screaming about how you should write the code to use your custom
PictureBox
class (the one on which you overrode theWndProc
function), rather than the built-in one. That's really a simple matter of changing all of the references toSystem::Windows::Forms::PictureBox
topictureBox1
(your custom class). Of course, you'll need to change the name of one or the other, but I recommend choosing better names than the default for everything.For example, try the following:
您创建了一个新类,但从未使用过它。
您需要将图片框更改为新类的实例。
但是,不要。WndProc
除非绝对必要,否则不应在 .Net 开发中使用;在这里,没有必要。您应该使用 .Net 事件。
You created a new class, but you never used it.
You need to change your picturebox to be an instance of your new class.
However, don't.WndProc
should not be used in .Net development unless absolutely necessary; here, it is not necessary.You should use .Net events.