MFC如何判断鼠标点击在了某非客户区域(注意,是整个桌面!)

MFC如何判断鼠标点击在了某非客户区域(注意,是整个桌面!)

我想在LButtonDown中响应,不知可行否?

0

3个回答

在你调用SetCapture(hWnd)函数后,只是能够捕获onmousedown、onmouseup、onmousemove、onclick、ondblclick、onmouseover和onmouseout鼠标消息,但是一般我们是捕获onmousemove和onmouseup两个消息。需要只注意最后一句“如果鼠标光标在另一个线程创建的窗口上,只有当鼠标键按下时系统才将鼠标输入指向指定的窗口”的解释,就是即使你在一个窗口线程里对了了SetCapture(),但你在别的窗口的上点击了同样会把鼠标消息发个这个窗口而是我们通过调用SetCapture()设定那个窗口。因为当鼠标在窗口外面点击的时候,被点击的窗口获得焦点,原来的SetCapture()也就失效了。

当你不在需要继续获得鼠标消息就要应该调用ReleaseCapture()释放掉,否则别的线程想调用就会失败。记住:SetCapture()和ReleaseCapture()必须成对呈现。
0

SetCapture()函数可以实现

0

解决方案1:
TME_NONCLIENT在WIN2000的DDK中有,你可以加上自定义
#ifndef TME_NONCLIENT
#define TME_NONCLIENT 0x00000010
#endif

解决方案2:
你看的那个例子这一句应该有问题,
只能:trmouse.dwFlags = TME_LEAVE | TME_HOVER;
没有标志:TME_NONCLIENT
以下是dwFlags:
TME_CANCEL The caller wants to cancel a prior tracking request.
The caller should also specify the type of tracking that it wants to cancel. For example, to cancel hover tracking, the caller must pass the TME_CANCEL and

TME_HOVER The caller wants hover notification. Notification is delivered as a WM_MOUSEHOVER message.
If the caller requests hover tracking while hover tracking is already active, the hover timer will be reset.
This flag is ignored if the mouse pointer is not over the specified window or area.

TME_LEAVE The caller wants leave notification. Notification is delivered as a WM_MOUSELEAVE message.
If the mouse is not over the specified window or area, a leave notification is generated immediately and no further tracking is performed.

TME_QUERY The function fills in the structure instead of treating it as a tracking request. The structure is filled such that had that structure been passed to TrackMouseEvent it would generate the current tracking. The only anomaly is that the hover timeout returned is always the actual timeout and not HOVER_DEFAULT, if HOVER_DEFAULT was specified during the original TrackMouseEvent request.

-1
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!