1. //拦截鼠标消息,edata有新招。
    2. public class TestMessageFilter : IMessageFilter
    3. {
    4. internal Form1 _Window { get; set; } = null;
    5. const int WM_MOUSEMOVE = 0x200;
    6. public bool PreFilterMessage(ref Message m)
    7. {
    8. if (m.Msg == WM_MOUSEMOVE)
    9. {
    10. if (_Window != null)
    11. {
    12. _Window.Text = "移动" + Cursor.Position.X.ToString() + "," + Cursor.Position.Y.ToString();
    13. }
    14. // return true;
    15. return false;
    16. }
    17. return false;
    18. }
    19. }
    20. public partial class Form1 : Form
    21. {
    22. public Form1()
    23. {
    24. InitializeComponent();
    25. TestMessageFilter t1 = new TestMessageFilter();
    26. t1._Window = this;
    27. Application.AddMessageFilter(t1);
    28. }
    29. }
    30. // if (g_MsgFilter != null)
    31. // {
    32. // Application.RemoveMessageFilter(g_MsgFilter);
    33. // g_MsgFilter = null;
    34. // }

    image.png