代码如下:
重写窗体的WndProc事件,截获windows消息并处理,但是发现一个奇怪的现象,就是当鼠标没有移动的时候,也会产生鼠标移动消息512,不知是为何,求大神不吝赐教。
protected override void WndProc(ref Message m)
{
if (m.Msg >= 512 && m.Msg <= 522)//截获所有鼠标事件消息
{
//Console.WriteLine("当前鼠标Windows消息:" + m.Msg);
Point currP = Cursor.Position;
//Console.WriteLine(string.Format("currP的X值为:{0},Y的值为:{1}", currP.X, currP.Y));
//Console.WriteLine(string.Format("globalP的X值为:{0},Y的值为:{1}", globalP.X, globalP.Y));
Console.WriteLine("触发了鼠标系列事件{0}", m.Msg);
isShow = false;
if (m.Msg == 512)
{
if (globalP.X == -1 && globalP.Y == -1)
{
//表示首次进来为初始值时,不做判断,只赋值,便于下次判断
globalP = currP;
}
else
{
if ((globalP.X != currP.X) && (globalP.Y != currP.Y))
{
isShow = false; //return;
}
else
{
Console.WriteLine(string.Format("currP的X值为:{0},Y的值为:{1}", currP.X, currP.Y));
Console.WriteLine(string.Format("globalP的X值为:{0},Y的值为:{1}", globalP.X, globalP.Y));
//Console.WriteLine("512设置为true了======================================");
isShow = true; //return;
}
}
}
}
else if (m.Msg == 0x0100 || m.Msg == 0x0101)//截获所有键盘事件消息 0x0100
{
//Console.WriteLine("当前键盘Windows消息:" + m.Msg);
//this.Hide();
Console.WriteLine("触发了键盘系列事件{0}", m.Msg);
isShow = false;
//return;
}
//else { isShow = true;
// //Console.WriteLine("触发了其他系列事件{0}", m.Msg);
//}
base.WndProc(ref m);
}
<audio controls="controls" style="display:none;"></audio>