Using System;
Using System.Collections.Generic;
Using System.ComponentModel;
Using System.Data;
Using System.Drawing;
Using System.Linq;
Using System.Text;
Using System.Windows.Forms;
Namespace SysInfo
{
public partial class Frm_main:form
{
MessageFilter MF = new MessageFilter ();
Public Frm_main ()
{
InitializeComponent ();
}
Form Load Message Filter
private void Frm_main_load (object sender, EventArgs e)
{
Add message filters to monitor these messages when a Windows message is delivered to the destination
Application.addmessagefilter (MF);
}
Remove a message filter from a form
private void Frm_main_formclosing (object sender, FormClosingEventArgs e)
{
Remove a message filter from the application's message pump
Application.removemessagefilter (MF);
}
Method One, rewrite WndProc virtual method, and method two cannot exist simultaneously
protected override void WndProc (ref Message m)
{
Switch (M.MSG)//Determine the ID number of the system message
{
Case 513:
MessageBox.Show ("Click the left mouse button! "," System Information ");
M.result = (INTPTR) 0;//The value returned to Windows in response to message processing
Break
Case 516:
MessageBox.Show ("right mouse click!") "," System Information ");
M.result = (INTPTR) 0;//The value returned to Windows in response to message processing
Break
Default
Base. WndProc (ref m);
Break
}
}
}
Method Two, implement the IMessageFilter interface to obtain Windows messages, and method one cannot exist simultaneously
public class Messagefilter:imessagefilter
{
public bool Prefiltermessage (ref message message)
{
Switch (message. MSG)//Determine the ID number of the system message
{
Case 513:
MessageBox.Show ("Click the left mouse button! "," System Information ");
return true;
Case 516:
MessageBox.Show ("right mouse click!") "," System Information ");
return true;
Default
return false;
}
}
}
}
Monitor mouse click left or right button