C++ cli 在类中重写wndproc

C++ cli 在类中重写wndproc,c++-cli,wndproc,C++ Cli,Wndproc,我遇到了我无法解决的问题,所以也许我在这里会有一些运气。我在我的应用程序中覆盖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::C

我遇到了我无法解决的问题,所以也许我在这里会有一些运气。我在我的应用程序中覆盖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;
}
请注意,这只是我猜测的逻辑版本。我们将不胜感激

彼得

我添加了整个wndproc,因为我坚信事件引发可能会变得棘手,因为我在函数中使用了中断

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);
}

这是行不通的。考虑一个事件,而不是通过M。您的控制器可以订阅活动。我当然认为这样做是可能的。在写这篇文章之前,我看了这里,实际上我在谷歌上搜索了一段时间,发现似乎很少有人能让它正常工作,但我不知道如何在我的特殊情况下做到这一点。这需要Marshal::GetFunctionPointerForDelegate()。有很多方法可以拍到你的脚,这样做,一个事件更容易得到正确的。嗯。。好的,你介意详细谈谈你的活动想法吗?我不太确定该怎么做,如果你认为这是一个好方法,那么对于那些遇到类似问题的人来说,这可能是一个很好的解决办法。
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);
}