正常情况下,鼠标指针位于哪个窗口区域内,鼠标消息就自动发给哪个窗口。如果调用了SetCapture,之后无论鼠标的位置在哪,鼠标消息都发给指定的这个窗口,直到调用ReleaseCapture或者调用SetCapture设置另一个窗口为止。
很多时候,窗口或控件在鼠标按下后,需要知道鼠标移动和放开的情况,例如按钮在鼠标按下后会变为“按下”状态,鼠标移出按钮区域时“弹起”,所以按钮控件需要在鼠标按下时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

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,或者在其他窗口点击 才结束

最新文章

  1. Enterprise Integration Pattern - 组成简介
  2. http请求提交cookie
  3. C#--参数数组
  4. 将Extjs文件拷入eclipse工程下卡死问题
  5. 开始学习node.js了,第一节,fs文件系统 【fs.rename】重命名文件/文件夹
  6. 深入了解View实现原理以及自定义View详解
  7. 解决Collection <__NSArrayM: 0x7f8168f7a750> was mutated while being enumerated.'
  8. 侧滑UI
  9. IE6-7下margin-bottom不兼容解决方法(非原创,视频中看到的)
  10. sqlserver提高篇
  11. RoboCup仿真3D TC笔记(2014年合肥中国公开赛 仿真3D比赛环境搭建)
  12. vue-cli2.9.1如何自动打开浏览器及实现手机调试
  13. Java开源生鲜电商平台-异常模块的设计与架构(源码可下载)
  14. linux下ftp服务器搭建
  15. nginx 部署前期一定要关闭selinux
  16. 【右滑返回】滑动冲突 Scroller DecorView
  17. DataStage 一、安装
  18. LeetCode赛题394----Decode String
  19. 洛谷P4644 [USACO2005 Dec]Cleaning Shifts 清理牛棚 [DP,数据结构优化]
  20. 并发编程 - io模型 - 总结

热门文章

  1. Java 集合类(一)
  2. oracle 条件:1=1或1=0,动态添加条件
  3. Leetcode#143 Reorder List
  4. MemSQL Start[c]UP 2.0 - Round 1
  5. [转载]JS中如何定义全局变量
  6. SCI杂志更名时,如何计算影响因子?
  7. PHP杂记
  8. script是什么
  9. 趣味Python入门(一):初识Python
  10. 【面试题021】包含min函数的栈