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;
}
}
更新时间: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;
}
}
相关文章推荐
- DirectX Sample分析:Framework中的控件事件绑定(二)
- DirectX Sample分析:Framework中的控件的显示步骤
- android ListView控件操作绑定数据、单击事件
- JQuery实现click事件绑定与触发方法分析
- GridView 动态绑定控件 OnRowCommand事件触发
- c# 事件方法与窗口或控件的绑定
- ASP.NET-008—JS绑定控件事件
- jQuery实现为动态添加的元素绑定事件实例分析
- jQuery on()方法给动态生成的元素绑定事件----实战分析
- android关于多个控件绑定相同事件的问题
- Android开发学习笔记:为动态添加的EditText控件绑定值改变监听事件
- jQuery源码分析-10事件处理-Event-事件绑定与删除-bind/unbind+live/die+delegat/undelegate
- chrome控制台查看控件有没绑定事件[转]
- Atlas脚本框架下为控件重复添加和绑定事件处理函数
- Android为按钮控件绑定事件的五种实现方式
- 如何将回车提交表单事件绑定到textbox控件?
- C#无边框窗体移动 将事件绑定到想实现的控件上
- jQuery源码分析--event事件绑定(上)
- Android中各种控件的绑定事件的优先级以及影响力
- gridview控件自定义绑定,响应模板列按钮事件