Register Form window message filter : Message « Event « C# / C Sharp






Register Form window message filter

Register Form window message filter

  using System;
  using System.Windows.Forms;
  using Microsoft.Win32;

  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;
    }
  }

  public class mainForm : System.Windows.Forms.Form
  {
    private MyMessageFilter msgFliter = new MyMessageFilter();

    public mainForm()
    {
      GetStats();
      Application.ApplicationExit += new EventHandler(Form_OnExit);
      Application.AddMessageFilter(msgFliter);    
    }

    [STAThread]
    static void Main() 
    {
      Application.Run(new mainForm());
    }

    private void GetStats()
    {
      Console.WriteLine(Application.CompanyName+ "  Company:");
      Console.WriteLine(Application.ProductName+ " App Name:");
      Console.WriteLine(Application.StartupPath);
    }

    // Event handlers.
    private void Form_OnExit(object sender, EventArgs evArgs) 
    {
      Console.WriteLine("Exit", "This app is dead...");
      Application.RemoveMessageFilter(msgFliter);
    }
  }


           
       








Related examples in the same category

1.Cast event sender to a control