0

我的表格控件使用无窗口复选框(因为这里可以有任意数量的复选框)。现在,我使用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正确?谢谢。

4

1 回答 1

0

您所说的基本上是正确的,尽管真正的复选框WM_MOUSEMOVE在“单击模式”下会跟踪,并且如果鼠标移开复选框,则会以原始状态显示复选框。所以要模仿你应该有:

on WM_MOUSEMOVE
    if we are in checkbox clicking mode
        if mouse is over the checkbox
            draw the checkbox in the pressed (toggled) state
        else
            draw the checkbox in the original state
于 2015-02-25T23:29:55.200 回答