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;
窗体继承接口如下:
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#仿QQ皮肤-Windows消息提示框窗体MessageBoxForm的实现
- 在C#中实现消息过滤
- C#编写Windows服务程序 (服务端),client使用 消息队列 实现淘宝 订单全链路效果
- C#编写Windows服务程序 (服务端),客户端使用 消息队列 实现淘宝 订单全链路效果
- [原创]C#应用WindowsApi实现查找\枚举(FindWindow、EnumChildWindows)窗体控件,并发送消息。
- C#应用WindowsApi实现查找\枚举(FindWindow、EnumChildWindows)窗体控件,并发送消息。
- C#的Windows编程中多语言的实现
- 用托盘控制windows服务的c#实现
- C#实现ip 地址过滤功能
- 如何在C#用WM_COPYDATA消息来实现两个进程之间传递数据
- 用C#在WINDOWS中实现新用户帐号的创建
- C# 使用重载消息处理函数的方式,实现没有标题栏的窗体的拖动。
- C#实现ip 地址过滤功能
- 关于C#中实现两个应用程序消息通讯的问题
- C#的Windows编程中多语言的实现
- 利用Windows消息循环实现消息延迟和消息合并
- 利用C#实现标注式消息提示窗口
- 使用C#代码实现增加 windows 用户帐号
- 使用C#编程将websphere MQ 5.3 windows客户端消息发送到linux服务器端
- 摘:用托盘控制windows服务的c#实现