Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tryed to buid a MessageFilter, but I don't know how to override the PreFilterMessage method correctly.

I tryed:
public ref class MyMessageFilter : System::Windows::Forms::IMessageFilter{
public: MyMessageFilter(){
    }
virtual bool PreFilterMessage(Message^objMessage) override{
                    if(objMessage->WParam.ToInt32() == 27)
                        return true;
                    return false;
            }
};


But I get an error:
error C3766: "MyMessageFilter" muss eine Implementierung für die bool System::Windows::Forms::IMessageFilter::PreFilterMessage (System::Windows::Forms::Message %)-Schnittstellenmethode bereitstellen.

What am I doing wrong? Thanks for your help!
Posted

You did not declare the method to override. You tell the compiler you are declaring it for the first time and with virtual you indicate it could be overridden using override.

Try this:
public ref class MyMessageFilter : System::Windows::Forms::IMessageFilter{public: MyMessageFilter(){    }

override bool PreFilterMessage(Message^objMessage) override{                    
   return objMessage->WParam.ToInt32() == 27;
}
};


http://msdn.microsoft.com/en-us/library/9fkccyh4(VS.71).aspx[^]


Good luck!
 
Share this answer
 
v2
Comments
egon_ll 3-Aug-10 15:52pm    
I think there is still a mistake. Now I get three more errors:

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C2217: "override" requires "virtual"
error C2144: 'bool' should be preceded by ';'
E.F. Nijboer 4-Aug-10 3:30am    
My german error messages aren't that good ;-) But I also made a mistake myself because you implement an interface and are not declaring a subclass. It should be:
public bool PreFilterMessage(Message^objMessage) {...}
I guess it should already go better with this declaration. Let me no if this raises any other errors.
egon_ll 6-Aug-10 3:05am    
Sorry I forgot to translate them. But I did now. Still the same error...
E.F. Nijboer 6-Aug-10 4:10am    
Seems like you where right about the virtual bool PreFilterMessage, but without the override. Have a look at this example, I think this might help. http://msdn.microsoft.com/en-us/library/ms171538.aspx
egon_ll 6-Aug-10 9:27am    
Thank you!! That really helped me! It had to be:
virtual bool PreFilterMessage(Message%m)
It still gives the same error:

error C3766: 'MyMessageFilter' must provide an implementation for the interface method 'bool System::Windows::Forms::IMessageFilter::PreFilterMessage(System::Windows::Forms::Message %)'
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900