如何在光标移出应用程序时获取光标位置 [英] how to get the cursor position when it goes outside of the application

查看:105
本文介绍了如何在光标移出应用程序时获取光标位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小问题,我试图将一些文件从我的应用程序中删除到应用程序之外,这里我可以获得光标位置,当它超出应用程序时,我使用了getcursorposition,但是用那个坐标我无法识别它是否在我的应用程序中。

解决方案

您知道您可能将屏幕坐标转换为客户端(或反之亦然)。

作为替代方案,您可以检测鼠标指针何时从应用程序窗口退出(请参阅​​ WM_MOUSELEAVE消息 [ ^ ]。


无论在哪里,您都可以获得鼠标光标的位置。要转换窗口坐标系中的坐标,可以使用窗口的屏幕坐标。



但问题是:什么事件会触发你的代码?您响应应用程序之外的鼠标事件,您需要捕获鼠标。具体如下:

SetCapture函数(Windows) [ ^ ],

ReleaseCapture函数(Windows) [ ^ ],

GetCapture函数(Windows) [ ^ ]。



另请参阅我对解决方案1的评论。



-SA


谢谢你们每一个我获取解决方案  


I have a small problem, i am trying to drop some file from my application to outside of the application, here how i can get the cursor position when it goes outside of the application, i used getcursorposition, but with that coordinate i can't able to identify it is in my application or not.

解决方案

You know you might convert screen coordinates to client ones (or viceversa).
As an alternative, you might detect when the mouse pointer 'exits' from your application window (see WM_MOUSELEAVE message[^]).


You can get the position of the mouse cursor, no matter where it is. To transform the coordinates in the coordinate system of your window, you can use the screen coordinates of your window.

But the problem is: what event would trigger your code? You respond to mouse events outside of your application, you would need to capture the mouse. This is how:
SetCapture function (Windows)[^],
ReleaseCapture function (Windows)[^],
GetCapture function (Windows)[^].

See also my comment to Solution 1.

—SA


Thank you every one i get the solution for this.


这篇关于如何在光标移出应用程序时获取光标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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