您的位置:首页 > 其它

DirectX Sample分析:Framework中的控件事件绑定(一)

2004-12-16 13:40 615 查看
作者:Junhot

更新时间:2004-12-15

-------------------------------------------------------------------------------

总的流程描述图:

        public override bool HandleMouse(NativeMethods.WindowMessage msg, System.Drawing.Point pt, IntPtr wParam, IntPtr lParam)

                // 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;

                        }

                    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: