windows应用开发由浅入深(三)有关鼠标事件--设置鼠标点击测试值实现非标题栏拖动窗口
2014-03-06 10:49
826 查看
相关消息:WM_NCHITTEST
MSDN描述:The WM_NCHITTEST message is sent to a window when the cursor moves, or when a mouse button is pressed or released. If the mouse is not captured, the message is sent to the window beneath the cursor. Otherwise, the message is sent
to the window that has captured the mouse.
当鼠标移动、或者点击/释放按钮时,发出WM_NCHITTEST消息给对应窗口。
相关消息宏:ON_WM_NCHITTEST()
相关处理函数:LRESULT OnNcHitTest(CPoint)
MSDN描述:The framework calls this member function for the CWnd object that contains the cursor (or the
CWnd object that used the SetCapture member function to capture the mouse input) every time the mouse is moved.
当鼠标移动时, MFC框架总是调用这个属于CWnd对象的成员函数,这个对象包含了鼠标指针的状态、或者说是这个对象使用了SetCapture这个成员函数捕获了鼠标的输入。
每当鼠标在窗口移动的时候,总会产生WM_NCHITTEST消息,这个消息被成员函数OnNcHitTest(CPoint)处理。成员函数OnNcHitTest将返回鼠标点击测试枚举值(即、鼠标位置)。要实现非标题栏拖动窗口,这种思路是通过改变鼠标点击测试值、使鼠标在窗口上拖动的事件改变为在标题栏拖动的事件。这种实现方式的基础在于、MFC将鼠标点击事件处理和获取鼠标坐标分开执行。一方面,鼠标移动不断产生WM_NCHITTEST消息,这个消息不断更新鼠标在窗口的位置;另一方面,鼠标点击时,使用WM_NCHITTEST消息处理程序更新的鼠标位置来做对应处理。这样,当鼠标位置值为HTCLIENT时,将其修改为HTCAPTION,即可让鼠标在窗口非标题栏拖动事件改为标题栏拖动事件。
但是这样的做法并不合理,因为标题栏如果有其他的左键单击/击、右键单/双击、甚至滚动事件处理,那么这些动作在非标题栏上也会响应。
这只是提供一个思路,很有意思。
附:
鼠标点击测试枚举值如下:
HTBORDER In the border of a window that does not have a sizing border. //在不具有可变大小边框的窗口的边框上
HTBOTTOM In the lower horizontal border of the window. //在窗口的水平边框的底部
HTBOTTOMLEFT In the lower-left corner of the window border. //在窗口边框的左下角
HTBOTTOMRIGHT In the lower-right corner of the window border. //在窗口边框的右下角
HTCAPTION In a title-bar area. //在标题栏区域内
HTCLIENT In a client area. //在客户区内
HTERROR On the screen background or on a dividing line between windows (same as
HTNOWHERE except that the DefWndProc Windows function produces a system beep to indicate an error). //在屏幕背景或窗口之间的分隔线上(与HTNOWHERE相同,除了Windows的DefWndProc函数产生一个系统响声以指明错误)
HTGROWBOX In a size box. //在尺寸框中
HTHSCROLL In the horizontal scroll bar. //在水平滚动条中
HTLEFT In the left border of the window. //在窗口左边框上
HTMAXBUTTON In a Maximize button. //在最大化按钮上
HTMENU In a menu area.
//在菜单区上
HTMINBUTTON In a Minimize button. //在最小化按钮上
HTNOWHERE On the screen background or on a dividing line between windows. //在屏幕背景或者窗口分割线上
HTREDUCE In a Minimize button. //在最小化按钮上
HTRIGHT In the right border of the window. //在窗口右边框上
HTSIZE In a size box (same as HTGROWBOX). //在尺寸框中
HTSYSMENU In a Control menu or in a Close button in a child window. //在控制菜单上或子窗口关闭按钮上
HTTOP In the upper horizontal border of the window. //在窗口水平框顶端
HTTOPLEFT In the upper-left corner of the window border. //在窗口左上角
HTTOPRIGHT In the upper-right corner of the window border. //在窗口右上角
HTTRANSPARENT In a window currently covered by another window. //在一个被其他窗口覆盖的窗口中
HTVSCROLL In the vertical scroll bar. //在垂直滚动条上
HTZOOM In a Maximize button. //在最大化按钮上
MSDN描述:The WM_NCHITTEST message is sent to a window when the cursor moves, or when a mouse button is pressed or released. If the mouse is not captured, the message is sent to the window beneath the cursor. Otherwise, the message is sent
to the window that has captured the mouse.
当鼠标移动、或者点击/释放按钮时,发出WM_NCHITTEST消息给对应窗口。
相关消息宏:ON_WM_NCHITTEST()
相关处理函数:LRESULT OnNcHitTest(CPoint)
MSDN描述:The framework calls this member function for the CWnd object that contains the cursor (or the
CWnd object that used the SetCapture member function to capture the mouse input) every time the mouse is moved.
当鼠标移动时, MFC框架总是调用这个属于CWnd对象的成员函数,这个对象包含了鼠标指针的状态、或者说是这个对象使用了SetCapture这个成员函数捕获了鼠标的输入。
每当鼠标在窗口移动的时候,总会产生WM_NCHITTEST消息,这个消息被成员函数OnNcHitTest(CPoint)处理。成员函数OnNcHitTest将返回鼠标点击测试枚举值(即、鼠标位置)。要实现非标题栏拖动窗口,这种思路是通过改变鼠标点击测试值、使鼠标在窗口上拖动的事件改变为在标题栏拖动的事件。这种实现方式的基础在于、MFC将鼠标点击事件处理和获取鼠标坐标分开执行。一方面,鼠标移动不断产生WM_NCHITTEST消息,这个消息不断更新鼠标在窗口的位置;另一方面,鼠标点击时,使用WM_NCHITTEST消息处理程序更新的鼠标位置来做对应处理。这样,当鼠标位置值为HTCLIENT时,将其修改为HTCAPTION,即可让鼠标在窗口非标题栏拖动事件改为标题栏拖动事件。
但是这样的做法并不合理,因为标题栏如果有其他的左键单击/击、右键单/双击、甚至滚动事件处理,那么这些动作在非标题栏上也会响应。
这只是提供一个思路,很有意思。
附:
鼠标点击测试枚举值如下:
HTBORDER In the border of a window that does not have a sizing border. //在不具有可变大小边框的窗口的边框上
HTBOTTOM In the lower horizontal border of the window. //在窗口的水平边框的底部
HTBOTTOMLEFT In the lower-left corner of the window border. //在窗口边框的左下角
HTBOTTOMRIGHT In the lower-right corner of the window border. //在窗口边框的右下角
HTCAPTION In a title-bar area. //在标题栏区域内
HTCLIENT In a client area. //在客户区内
HTERROR On the screen background or on a dividing line between windows (same as
HTNOWHERE except that the DefWndProc Windows function produces a system beep to indicate an error). //在屏幕背景或窗口之间的分隔线上(与HTNOWHERE相同,除了Windows的DefWndProc函数产生一个系统响声以指明错误)
HTGROWBOX In a size box. //在尺寸框中
HTHSCROLL In the horizontal scroll bar. //在水平滚动条中
HTLEFT In the left border of the window. //在窗口左边框上
HTMAXBUTTON In a Maximize button. //在最大化按钮上
HTMENU In a menu area.
//在菜单区上
HTMINBUTTON In a Minimize button. //在最小化按钮上
HTNOWHERE On the screen background or on a dividing line between windows. //在屏幕背景或者窗口分割线上
HTREDUCE In a Minimize button. //在最小化按钮上
HTRIGHT In the right border of the window. //在窗口右边框上
HTSIZE In a size box (same as HTGROWBOX). //在尺寸框中
HTSYSMENU In a Control menu or in a Close button in a child window. //在控制菜单上或子窗口关闭按钮上
HTTOP In the upper horizontal border of the window. //在窗口水平框顶端
HTTOPLEFT In the upper-left corner of the window border. //在窗口左上角
HTTOPRIGHT In the upper-right corner of the window border. //在窗口右上角
HTTRANSPARENT In a window currently covered by another window. //在一个被其他窗口覆盖的窗口中
HTVSCROLL In the vertical scroll bar. //在垂直滚动条上
HTZOOM In a Maximize button. //在最大化按钮上
相关文章推荐
- windows应用开发由浅入深(三)利用注册表将程序启动时窗口位置设置为上次关闭的位置
- Java程序中取消窗口标题栏以及边框,并使窗口可以相应鼠标事件,被鼠标拖动;设置JFrame背景色
- windows应用开发由浅入深(三)有关不规则窗口
- 一周乱弹(1,摸态框增加纵向滚动条2,jQuery 鼠标点击事件3,通过ajax实现批量导出。4,windows查询占用某个端口号程序并杀死其进程)
- ArcGIS API for Silverlight开发中鼠标左键点击地图上的点弹出窗口及右键点击弹出快捷菜单的实现代码
- 百度地图开发,实现鼠标悬浮时间以及点击事件
- Java OpenCV开发——使用JavaCV在窗口显示图像,并监听鼠标点击事件
- windows应用开发由浅入深(二)有关控件的操作
- 百度地图开发,实现鼠标悬浮事件以及点击事件
- js鼠标事件解析——如何用js实现一个拖动但是不触发其点击事件
- JS实现鼠标点击拖动窗口方法
- 鼠标点击非标题栏区拖动MFC对话框(OnNcHitTest函数实现)
- qt实现类似QQ伸缩窗口--鼠标事件应用
- winForm 实现鼠标拖动标题栏不移动窗口 和 拖动用户区移动窗口
- qt实现类似QQ伸缩窗口--鼠标事件应用
- WPF下Window设置WindowStyle="None"时实现鼠标拖动移动窗口位置
- 实现用鼠标拖动没有标题栏的窗口(窗体的任何部分都可实现拖动效果)
- Unity3d实现检测鼠标点击2d object事件
- MFC在鼠标自定义的一定的范围内实现拖动窗口移动、错误:不支持尝试执行的操作、实现进度条颜色的渐变或者背景和前景色的改变
- windows系统对鼠标点击事件的处理过程