//拦截鼠标消息,edata有新招。
public class TestMessageFilter : IMessageFilter
{
internal Form1 _Window { get; set; } = null;
const int WM_MOUSEMOVE = 0x200;
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == WM_MOUSEMOVE)
{
if (_Window != null)
{
_Window.Text = "移动" + Cursor.Position.X.ToString() + "," + Cursor.Position.Y.ToString();
}
// return true;
return false;
}
return false;
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
TestMessageFilter t1 = new TestMessageFilter();
t1._Window = this;
Application.AddMessageFilter(t1);
}
}
// if (g_MsgFilter != null)
// {
// Application.RemoveMessageFilter(g_MsgFilter);
// g_MsgFilter = null;
// }