Application.RemoveMessageFilter
using System;
using System.Windows.Forms;
public class mainForm : System.Windows.Forms.Form
{
private MyMessageFilter msgFliter = new MyMessageFilter();
public mainForm()
{
Application.ApplicationExit += new EventHandler(Form_OnExit);
Application.AddMessageFilter(msgFliter);
}
[STAThread]
static void Main()
{
Application.Run(new mainForm());
}
private void Form_OnExit(object sender, EventArgs evArgs)
{
Application.RemoveMessageFilter(msgFliter);
}
}
public class MyMessageFilter : IMessageFilter
{
public bool PreFilterMessage(ref Message m)
{
// Intercept the left mouse button down message.
if (m.Msg == 513)
{
Console.WriteLine("WM_LBUTTONDOWN is: " + m.Msg);
return true;
}
return false;
}
}
Related examples in the same category