我遇到了无法解决的问题,所以也许我会在这里运气一下。我在我的申请中覆盖了WndProc:
#include "stdafx.h"
#include <Windows.h>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>
#using <System.dll>
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Drawing;
namespace EXAMPLE
{
public ref class Form1: public System::Windows::Forms::Form
{
public:
Form1()
{
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(GetSystemMetrics(SM_CXSCREEN)/2, GetSystemMetrics(SM_CYSCREEN)/2);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::Sizable;
this->Name = L"Test";
this->Text = L"Test";
this->ResumeLayout(false);
}
protected: virtual void WndProc(System::Windows::Forms::Message% m) override
{
//Do stuff in here
Form::WndProc(m);
}
};
}
[STAThreadAttribute]
int main()
{
Application::Run(gcnew projector_fixer::Form1() );
return 0;
}
这很好用但是因为我希望我的主要尽可能干净,所以我决定创建“控制器类”,通过连接main来处理所有事情。因此,例如,我不是在EXAMPLE命名空间中包含mouse_click的事件,而是在我的“控制器类”构造函数中包含单击的对象,并在此类中处理它。这很容易,但是当想要覆盖wndproc时,我意识到我不知道怎么做。我想它可能看起来像这样:
inside main
myclass ^MYCLASS=gcnew myclass(//some way to send wndproc override to function//);
MYCLASS.h
#pragma once
ref class MYCLASS
{
public:
MYCLASS();
overriden_wndproc(System::Windows::Forms::Message% m);
};
MYCLASS.cpp
MYCLASS::MYCLASS(//some way to send wndproc override to function//)
{
overriden_wndproc=//some way to send wndproc override to function//;
}
MYCLASS::overriden_wndproc(System::Windows::Forms::Message% m)
{
//Do stuff in here
Form::WndProc(m);
}
请注意,这只是我猜测的合乎逻辑的版本。非常感谢所有帮助。
彼得
我正在添加整个wndproc,因为我坚信事件提升可能会变得棘手,因为我在我的函数中使用break。
protected: virtual void WndProc(System::Windows::Forms::Message% m) override
{
System::Diagnostics::Debug::WriteLine(m);
switch(hZoomSwitch)
{
case 0:
{
hScrollBar1->Value=0;
hTimer->Stop();
hZoomSwitch=2;
break;
}
case 1:
{
hTimer->Start();
hZoomSwitch=2;
break;
}
}
switch(vZoomSwitch)
{
case 0:
{
vScrollBar1->Value=0;
vTimer->Stop();
vZoomSwitch=2;
break;
}
case 1:
{
vTimer->Start();
vZoomSwitch=2;
break;
}
}
Form::WndProc(m);
}