继承c ++ clr中的类

时间:2018-01-20 12:37:24

标签: visual-studio visual-c++ clr

我正在尝试使用模板CLR / Empty CLR项目在Visual Studio 2017中构建一个简单项目。我添加了对所需命名空间的引用,但是当我尝试继承“ IMessageFilter ”类时在我班上我得到以下错误,我该怎么办?

类无法实现接口成员函数“System :: Windows :: Forms :: IMessageFilter :: PreFilterMessage”(在“c:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework.NETFramework \”中声明v4.6.1 \ System.Windows.Forms.dll中“

#pragma once
using namespace System;
using namespace System::Windows::Forms;

ref class myClass : public IMessageFilter // this is not accepted by compiler with error
{
public:
    myClass();
};

1 个答案:

答案 0 :(得分:1)

如错误消息所示,您需要实现IMessageFilter接口所需的PreFilterMessage消息函数:

virtual bool PreFilterMessage(Message% message)
{
    // from MSDN: return true to filter the message and stop it from being dispatched; false to allow the message to continue to the next filter or control.
    return true;
};