您的位置:首页 > 编程语言 > C#

C# 实现 WINDOWS 消息过滤

2015-04-07 09:40 344 查看
窗体继承 IMessageFilter接口,重写PreFilterMessage方法,针对需要过滤或增加处理的事件代码进行判断,需要过滤的消息返回true,需要原封装控件继续处理的返回false,继续系统默认处理;

窗体继承接口如下:

Public partial class Form1:Form,ImessageFilter

实现PreFilterMessage事件如下:

Public bool PreFilterMessage(ref System.Windows.Forms.Message MyMessage)

{

     //不响应鼠标左键消息

    If(MyMessage.Msg>=513 && MyMessage.Msg<=515)

       {

         Return true;

       }

   Return false;

}

windows部分事件代码如下:

public const int WM_KEYDOWN = 0x100;

public const int WM_SYSKEYDOWN = 0x104;

public const int WM_KEYUP = 0x101;

public const int WM_SYSKEYUP = 0x105;

public const int WM_MOUSEMOVE = 0x200;

public const int WM_MOUSEHOVER = 0x2a1;

public const int WM_MOUSELEAVE = 0x2a3;

public const int WM_LBUTTONDOWN = 0x201;

public const int WM_LBUTTONUP = 0x202;

public const int WM_LBUTTONDBLCLK = 0x203;

public const int WM_RBUTTONDOWN = 0x204;

public const int WM_RBUTTONUP = 0x205;

public const int WM_RBUTTONDBLCLK = 0x206;

public const int WM_NCMOUSEMOVE = 0xa0;

public const int WM_NCLBUTTONDOWN = 0xa1;

public const int WM_NCLBUTTONUP = 0xa2;

public const int WM_MOUSEWHEEL = 0x20a;

public const int WM_PAINT = 0xf;

public const int WM_TIMER = 0x113;

public const int MK_LBUTTON = 0x0001;

public const int MK_RBUTTON = 0x0002;

public const int MK_SHIFT = 0x0004;

public const int MK_CONTROL = 0x0008;

public const int MK_MBUTTON = 0x0010;

public const int MK_XBUTTON1 = 0x0020;

public const int MK_XBUTTON2 = 0x0040;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  鼠标 控件 c#