很多時候,窗口或控件在鼠標按下后,需要知道鼠標移動和放開的情況,例如按鈕在鼠標按下后會變為“按下”狀態,鼠標移出按鈕區域時“彈起”,所以按鈕控件需要在鼠標按下時SetCapture,鼠標放開后ReleaseCapture。
GetCapture只是檢查一下當前是哪個窗口捕獲了鼠標,通常不需要調用。
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.
RemarksA 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並不一定就是說當前線程沒有捕捉到鼠標,完全有可能是另一個線程或進程捕捉到了鼠標。
作用:改變 MOUSEMOVE 消息默認發送方式.
一般移動 鼠標時,鼠標在哪個窗口 MOUSEMOVE 消息就發給哪個窗口(會觸發OnIdle),
不管這個窗口是不是當前窗口,也不管是不是擁有焦點,或者有沒有激活
而SetCapture 則會改變這種行為.當某個窗口被設置了SetCapture 后
鼠標在全屏范圍內移動時MouseMove 消息都會發送給該窗口.
直到 ReleaseCapture,或者在其他窗口點擊 才結束
參考:
http://hi.baidu.com/iaskall/item/15e52cf8ebfc72d742c36a63
函數功能:該函數在屬於當前線程的指定窗口里設置鼠標捕獲。一旦窗口捕獲了鼠標,所有鼠標輸入都針對該窗口,無論光標是否在窗口的邊界內。同一時刻只能有一個窗口捕獲鼠標。如果鼠標光標在另一個線程創建的窗口上,只有當鼠標鍵按下時系統才將鼠標輸入指向指定的窗口。
下面我舉一個例子,能簡單地理解SetCapture和ReleaseCapture的作用:
當你在瀏覽本日志的時候,你會拉動右手邊的滑動條來調整內容上下位置,那么當你按下左鍵的時候,移動鼠標到非滾動條處,你會發現上下移動鼠標滾動條仍然后控制,對,這就是俘獲鼠標函數SetCapture的作用。
參考:
http://blog.csdn.net/haussuden/article/details/5853365