Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 4
Application Class
Application Methods
 RemoveMessageFilter Method
Collapse All/Expand All Collapse All
.NET Framework Class Library
Application..::.RemoveMessageFilter Method

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

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
Visual Basic
Public Shared Sub RemoveMessageFilter ( _
    value As IMessageFilter _
)
C#
public static void RemoveMessageFilter(
    IMessageFilter value
)
Visual C++
public:
static void RemoveMessageFilter(
    IMessageFilter^ value
)
F#
static member RemoveMessageFilter : 
        value:IMessageFilter -> unit 

Parameters

value
Type: System.Windows.Forms..::.IMessageFilter
The implementation of the IMessageFilter to remove from the application.

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

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.
<SecurityPermission(SecurityAction.LinkDemand, Flags := SecurityPermissionFlag.UnmanagedCode)> _
Public Class TestMessageFilter
    Implements IMessageFilter

    <SecurityPermission(SecurityAction.Demand)> _
    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.
[SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
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;
    }
}

Visual C++
   // Creates a  message filter.
   ref class TestMessageFilter: public IMessageFilter
   {
   public:
      [SecurityPermission(SecurityAction::LinkDemand, Flags = SecurityPermissionFlag::UnmanagedCode)]
      virtual bool PreFilterMessage( Message % m )
      {

         // Blocks all the messages relating to the left mouse button.
         if ( m.Msg >= 513 && m.Msg <= 515 )
         {
            Console::WriteLine( "Processing the messages : {0}", m.Msg );
            return true;
         }

         return false;
      }

   };

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker