[图片]
[图片] // Mouse messages
[图片] case NativeMethods.WindowMessage.MouseMove:
[图片] case NativeMethods.WindowMessage.MouseWheel:
[图片] case NativeMethods.WindowMessage.LeftButtonUp:
[图片] case NativeMethods.WindowMessage.LeftButtonDown:
[图片] case NativeMethods.WindowMessage.LeftButtonDoubleClick:
[图片] case NativeMethods.WindowMessage.RightButtonUp:
[图片] case NativeMethods.WindowMessage.RightButtonDown:
[图片] case NativeMethods.WindowMessage.RightButtonDoubleClick:
[图片] case NativeMethods.WindowMessage.MiddleButtonUp:
[图片] case NativeMethods.WindowMessage.MiddleButtonDown:
[图片] case NativeMethods.WindowMessage.MiddleButtonDoubleClick:
[图片] case NativeMethods.WindowMessage.XButtonUp:
[图片] case NativeMethods.WindowMessage.XButtonDown:
[图片] case NativeMethods.WindowMessage.XButtonDoubleClick:
[图片][图片] [图片]{
[图片] // If not accepting mouse input, return false to indicate the message should still
[图片] // be handled by the application (usually to move the camera).
[图片] if (!usingMouseInput)
[图片] return false;
[图片]
[图片] // Current mouse position
[图片] short mouseX = NativeMethods.LoWord((uint)lParam.ToInt32());
[图片] short mouseY = NativeMethods.HiWord((uint)lParam.ToInt32());
[图片] System.Drawing.Point mousePoint = new System.Drawing.Point(mouseX, mouseY);
[图片] // Offset mouse point
[图片] mousePoint.X -= dialogX;
[图片] mousePoint.Y -= dialogY;
[图片]
[图片] // If caption is enabled, offset the Y coordinate by the negative of its height.
[图片] if (hasCaption)
[图片] mousePoint.Y -= captionHeight;
[图片]
[图片] // If a control is in focus, it belongs to this dialog, and it's enabled, then give
[图片] // it the first chance at handling the message.
[图片] if (controlFocus != null &&
[图片] controlFocus.Parent == this &&
[图片] controlFocus.IsEnabled)
[图片][图片] [图片]{
[图片] // If the control MsgProc handles it, then we don't.
[图片] if (controlFocus.HandleMouse(msg, mousePoint, wParam, lParam))
[图片] return true;
[图片] }
[图片]
[图片] // Not yet handled, see if the mouse is over any controls
[图片] Control control = GetControlAtPoint(mousePoint);
[图片] if ((control != null) && (control.IsEnabled))
[图片][图片] [图片]{
[图片] // Let the control handle the mouse if it wants (and return true if it handles it)
[图片] if (control.HandleMouse(msg, mousePoint, wParam, lParam))
[图片] return true;
[图片] }
[图片] else
[图片][图片] [图片]{
[图片] // Mouse not over any controls in this dialog, if there was a control
[图片] // which had focus it just lost it
[图片] if (msg == NativeMethods.WindowMessage.LeftButtonDown &&
[图片] controlFocus != null &&
[图片] controlFocus.Parent == this)
[图片][图片] [图片]{
[图片] controlFocus.OnFocusOut();
[图片] controlFocus = null;
[图片] }
[图片] }