SetCapture、ReleaseCapture、GetCapture
2024-10-19 04:29:23
正常情况下,鼠标指针位于哪个窗口区域内,鼠标消息就自动发给哪个窗口。如果调用了SetCapture,之后无论鼠标的位置在哪,鼠标消息都发给指定的这个窗口,直到调用ReleaseCapture或者调用SetCapture设置另一个窗口为止。
很多时候,窗口或控件在鼠标按下后,需要知道鼠标移动和放开的情况,例如按钮在鼠标按下后会变为“按下”状态,鼠标移出按钮区域时“弹起”,所以按钮控件需要在鼠标按下时SetCapture,鼠标放开后ReleaseCapture。
GetCapture只是检查一下当前是哪个窗口捕获了鼠标,通常不需要调用。
很多时候,窗口或控件在鼠标按下后,需要知道鼠标移动和放开的情况,例如按钮在鼠标按下后会变为“按下”状态,鼠标移出按钮区域时“弹起”,所以按钮控件需要在鼠标按下时SetCapture,鼠标放开后ReleaseCapture。
GetCapture只是检查一下当前是哪个窗口捕获了鼠标,通常不需要调用。
用微软的话来说:
Retrieves a handle to the window (if any) that has captured the mouse. Only one window at a time can capture the mouse; this window receives mouse input whether or not the cursor is within its borders.
Return value
Type: HWND
The return value is a handle to the capture window associated with the current thread. If no window in the thread has captured the mouse, the return value is NULL.
Remarks
A NULL return value means the current thread has not captured the mouse. However, it is possible that another thread or process has captured the mouse.
尤其要注意,如果返回值为NULL并不一定就是说当前线程没有捕捉到鼠标,完全有可能是另一个线程或进程捕捉到了鼠标。
对于SetCapture/ReleaseCapture
作用:改变 MOUSEMOVE 消息默认发送方式.
一般移动 鼠标时,鼠标在哪个窗口 MOUSEMOVE 消息就发给哪个窗口(会触发OnIdle),
不管这个窗口是不是当前窗口,也不管是不是拥有焦点,或者有没有激活
而SetCapture 则会改变这种行为.当某个窗口被设置了SetCapture 后
鼠标在全屏范围内移动时MouseMove 消息都会发送给该窗口.
直到 ReleaseCapture,或者在其他窗口点击 才结束
作用:改变 MOUSEMOVE 消息默认发送方式.
一般移动 鼠标时,鼠标在哪个窗口 MOUSEMOVE 消息就发给哪个窗口(会触发OnIdle),
不管这个窗口是不是当前窗口,也不管是不是拥有焦点,或者有没有激活
而SetCapture 则会改变这种行为.当某个窗口被设置了SetCapture 后
鼠标在全屏范围内移动时MouseMove 消息都会发送给该窗口.
直到 ReleaseCapture,或者在其他窗口点击 才结束
最新文章
- Enterprise Integration Pattern - 组成简介
- http请求提交cookie
- C#--参数数组
- 将Extjs文件拷入eclipse工程下卡死问题
- 开始学习node.js了,第一节,fs文件系统 【fs.rename】重命名文件/文件夹
- 深入了解View实现原理以及自定义View详解
- 解决Collection <;__NSArrayM: 0x7f8168f7a750>; was mutated while being enumerated.&#39;
- 侧滑UI
- IE6-7下margin-bottom不兼容解决方法(非原创,视频中看到的)
- sqlserver提高篇
- RoboCup仿真3D TC笔记(2014年合肥中国公开赛 仿真3D比赛环境搭建)
- vue-cli2.9.1如何自动打开浏览器及实现手机调试
- Java开源生鲜电商平台-异常模块的设计与架构(源码可下载)
- linux下ftp服务器搭建
- nginx 部署前期一定要关闭selinux
- 【右滑返回】滑动冲突 Scroller DecorView
- DataStage 一、安装
- LeetCode赛题394----Decode String
- 洛谷P4644 [USACO2005 Dec]Cleaning Shifts 清理牛棚 [DP,数据结构优化]
- 并发编程 - io模型 - 总结