windows应用开发由浅入深(三)有关鼠标事件--设置鼠标点击测试值实现非标题栏拖动窗口

相关消息: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.                                                                                 //在最大化按钮上


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值