UIControl.5.WndProc.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Windows.Forms;
  3. using Microsoft.Win32;
  4. namespace Microsoft.Windows.Forms
  5. {
  6. partial class UIControl
  7. {
  8. /// <summary>
  9. /// 消息处理
  10. /// </summary>
  11. /// <param name="m">消息</param>
  12. protected internal virtual void WndProc(ref Message m)
  13. {
  14. switch (m.Msg)
  15. {
  16. case NativeMethods.WM_LBUTTONDOWN:
  17. this.OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, Util.GET_X_LPARAM(m.LParam), Util.GET_Y_LPARAM(m.LParam), 0));
  18. break;
  19. case NativeMethods.WM_LBUTTONDBLCLK:
  20. if (this.Capture)
  21. this.OnDoubleClick(new MouseEventArgs(MouseButtons.Left, 2, Util.GET_X_LPARAM(m.LParam), Util.GET_Y_LPARAM(m.LParam), 0));
  22. break;
  23. case NativeMethods.WM_LBUTTONUP:
  24. this.OnMouseUp(new MouseEventArgs(MouseButtons.Left, 1, Util.GET_X_LPARAM(m.LParam), Util.GET_Y_LPARAM(m.LParam), 0));
  25. if (this.Capture)
  26. this.OnClick(EventArgs.Empty);
  27. break;
  28. case NativeMethods.WM_MOUSEMOVE:
  29. MouseButtons buttons = MouseButtons.None;
  30. int wParam = m.WParam.ToInt32();
  31. if ((wParam & NativeMethods.MK_LBUTTON) != 0)
  32. buttons &= MouseButtons.Left;
  33. if ((wParam & NativeMethods.MK_RBUTTON) != 0)
  34. buttons &= MouseButtons.Right;
  35. if ((wParam & NativeMethods.MK_MBUTTON) != 0)
  36. buttons &= MouseButtons.Middle;
  37. if ((wParam & NativeMethods.MK_XBUTTON1) != 0)
  38. buttons &= MouseButtons.XButton1;
  39. if ((wParam & NativeMethods.MK_XBUTTON2) != 0)
  40. buttons &= MouseButtons.XButton2;
  41. this.OnMouseMove(new MouseEventArgs(buttons, 1, Util.GET_X_LPARAM(m.LParam), Util.GET_Y_LPARAM(m.LParam), 0));
  42. break;
  43. }
  44. this.State = this.GetState();
  45. }
  46. }
  47. }