0

我遇到了我无法解决的问题,所以也许我会在这里碰碰运气。我在我的应用程序中覆盖 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 尽可能干净,所以我决定创建“控制器类”,通过与 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);
}
4

0 回答 0