This documentation is archived and is not being maintained.

Application.RemoveMessageFilter Method

Removes a message filter from the message pump of the application.

[Visual Basic]
Public Shared Sub RemoveMessageFilter( _
   ByVal value As IMessageFilter _
)
[C#]
public static void RemoveMessageFilter(
 IMessageFilter value
);
[C++]
public: static void RemoveMessageFilter(
 IMessageFilter* value
);
[JScript]
public static function RemoveMessageFilter(
   value : IMessageFilter
);

Parameters

value
The implementation of the IMessageFilter to remove from the application.

Remarks

You can remove a message filter when you no longer want to capture Windows messages before they are dispatched.

Example

[Visual Basic, C#, C++] Before you can use a message filter, you must provide an implementation for the IMessageFilter interface. The following class creates a message filter called TestMessageFilter. This filter blocks all messages relating to the left mouse button.

[Visual Basic] 
' Creates a message filter.
Public Class TestMessageFilter
   Implements IMessageFilter

   Public Function PreFilterMessage(ByRef m As System.Windows.Forms.Message) _
   As Boolean Implements IMessageFilter.PreFilterMessage
      ' Blocks all the messages relating to the left mouse button.
      If ((m.Msg >= 513) And (m.Msg <= 515)) Then
         Console.WriteLine("Processing the messages : " & m.Msg)
         Return True
      End If
      Return False
   End Function
End Class


[C#] 
// Creates a  message filter.
 public class TestMessageFilter : IMessageFilter {
    public bool PreFilterMessage(ref Message m) {
       // Blocks all the messages relating to the left mouse button.
       if (m.Msg >= 513 && m.Msg <= 515) {
          Console.WriteLine("Processing the messages : " + m.Msg);
          return true;
       }
       return false;
    }
  }


[C++] 
// Creates a  message filter.
public:
__gc class TestMessageFilter : public IMessageFilter {
public:
   bool PreFilterMessage(Message* m) {
      // Blocks all the messages relating to the left mouse button.
      if (m->Msg >= 513 && m->Msg <= 515) {
         Console::WriteLine(S"Processing the messages : {0}", __box(m->Msg));
         return true;
      }
      return false;
   }
};

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

Application Class | Application Members | System.Windows.Forms Namespace | AddMessageFilter

Show: