I am trying to build a simple project in Visual Studio 2017 using the template CLR/Empty CLR project .. I have added references to required namespaces, but when I try to inherit "IMessageFilter" class in my class I get below error, What should I do?
class fails to implement interface member function "System::Windows::Forms::IMessageFilter::PreFilterMessage" (declared in "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();
};
As the error message suggests, you need to implement the PreFilterMessage message function that is required by the IMessageFilter interface:
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;
};