按住鼠标左键时未生成 WM_MOUSELEAVE [英] WM_MOUSELEAVE not being generated when left mouse button is held

查看:61
本文介绍了按住鼠标左键时未生成 WM_MOUSELEAVE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Win32 应用程序中,当我按住鼠标左键并快速将鼠标指针移出窗口时,我没有收到 WM_MOUSELEAVE 消息.但是如果我按住鼠标左键,从窗口内部开始,慢慢地移过窗口边缘,它会生成一个 WM_MOUSELEAVE.

In my Win32 app, I don't get WM_MOUSELEAVE messages when I hold down the left mouse button and quickly move the mouse pointer out of the window. But If I, holding down the left mouse button, start from the inside of the window and move slowly past the window edge, it'll generate a WM_MOUSELEAVE.

如果我不按住鼠标左键,无论鼠标指针移出窗口的速度有多快,我每次都会收到 WM_MOUSELEAVE 消息.

If I don't hold the left mouse button, I get WM_MOUSELEAVE messages every time no matter how fast the mouse pointer moves off the window.

有什么区别?我该怎么做才能正确处理这两种情况?

What's the difference? What can I do to handle both cases properly?

如果我左键单击并按住,移出窗口,然后松开鼠标左键,我会收到 WM_MOUSELEAVE 消息.但为时已晚.

If I left click and hold, move out of the window and then let go of the left mouse button I get the WM_MOUSELEAVE message. But it's way too late.

推荐答案

WM_MOUSELEAVE 使您可以在没有捕获时检测鼠标离开窗口.当您捕获时,您有责任自己检测(如果您关心).

WM_MOUSELEAVE is so that you can detect the mouse leaving your window when you don't have capture. When you have capture, you are responsible for detecting that yourself (if you care).

因此同时使用 SetCaptureTrackMouseEvent 没有任何意义,您可以使用其中一个.

so It doesn't make any sense to SetCapture AND TrackMouseEvent at the same time, you would use one or the other.

现在,如果您在捕获时查看 WM_MOUSELEAVE 消息会更方便,那么在您的消息泵中自己完成此操作是一件相对简单的事情.

Now, if it would be more convenient for you to see the WM_MOUSELEAVE messages while you have capture, it's a relatively simple matter to do that by yourself in your message pump.

您只需在消息泵中的 GetMessage()DispatchMessage() 调用之间添加看起来像这样的代码.

You would just add code that looks something like this between the GetMessage() and the DispatchMessage() calls in your message pump.

  GetMessage(pmsg, ...);

  .....

  if ((IS_WITHIN(pmsg->message, WM_MOUSEFIRST, WM_MOUSELAST) ||
       IS_WITHIN(pmsg->message, WM_NCMOUSEMOVE, WM_NCMBUTTONDBLCLK)) &&
       MyMouseLeaveDetection(pmsg, g_hwndNotifyMouseLeave))
     {
     MSG msg = *pmsg;
     msg.message = WM_MOUSELEAVE;
     msg.hwnd    = g_hwndNotifyMouseLeave; // window that want's 
     msg.lParam  = 0xFFFFFFFF;
     g_hwndNotifyMouseLeave = NULL;

     DispatchMessage (&msg);
     }

 .....
 TranslateMessage(pmsg);
 DispatchMessage(pmsg);

这篇关于按住鼠标左键时未生成 WM_MOUSELEAVE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆