我的表格控件使用无窗口复选框(因为这里可以有任意数量的复选框)。现在,我使用TrackMouseEvent(TME_LEAVE)
并手动检查鼠标是否在WM_LBUTTONUP
. 我在我的代码中为由此导致的边缘情况标记了 TODO,例如WM_LBUTTONUP
鼠标离开客户区域时丢失。
现在我注意到今天的旧新事物说按钮使用鼠标捕获。这让我开始思考,在研究之后,鼠标捕获会更适合我的需要;如果我的假设是正确的,它将处理我上面提到的各种边缘情况,并且通常更正确。
特别是,我做出的假设是:WM_CAPTURECHANGED
即使满足所有其他条件,我也应该放弃任何与捕获相关的操作。我会得到一个WM_CAPTURECHANGED
后一个ReleaseCapture()
。在 a 之后SetCapture()
,我总是以 aWM_LBUTTONUP
或 a结尾WM_CAPTURECHANGED
,以先到者为准。
我已经阅读了 MSDN 和我通过谷歌搜索“setcapture 正确使用”找到的几篇文章;我只是想确保我有正确的想法并将正确实施。我吗?
on WM_LBUTTONDOWN
if the button is in a checkbox
SetCapture()
mark that we're in checkbox clicking mode
on WM_MOUSEMOVE
if we are in checkbox clicking mode
draw the checkbox in the pressed state
on WM_LBUTTONUP
if we are in checkbox clicking mode
leave checkbox clicking mode
THEN call ReleaseCapture(), so we can ignore its WM_CAPTURECHANGED
if the mouse was released in the same checkbox
toggle it
on WM_CAPTURECHANGED
if we are in checkbox clicking mode
abandon checkbox clicking mode and leave the checkbox untoggled, even if the mouse is hovering over the checkbox
我在这里有正确的想法吗?特别是,我的操作顺序是否WM_LBUTTONDOWN
正确?谢谢。