在多屏设置中隐藏鼠标光标
我试图使用 win32 API ShowCursor(FALSE) 隐藏鼠标光标,但在多屏幕设置中,当鼠标到达另一个屏幕时,我在 Windows 中没有收到任何鼠标更新。
有什么办法可以防止这种情况发生吗?
这是针对全屏视频游戏的,我似乎没有找到任何可以执行此类操作的 Windows api。
I am trying to hide the mouse cursor using win32 API ShowCursor(FALSE), but on a multiscreen setup when the mouse gets to the other screen I don't get any mouse updates in windows.
Is there any way I can prevent this?
This is for a fullscreen video game and I don't seem to find any windows api that can do something like this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我了解,您的问题不在于隐藏鼠标光标,而在于将其限制在您的窗口中?
在这种情况下,
ClipCursor
函数应该可以完成这项工作。
对于无边框全屏窗口,执行一次就可以了。如果窗口的位置或大小发生变化或窗口失去焦点,则需要重复该步骤。
对于游戏编程,可能有更好的方法,例如 DirectInput,它提供了专有的鼠标处理模式(教程可用)并在较低级别上为您完成所有这些工作。
有一些关于处理此问题的不同方法的讨论,例如 MSDN 论坛上的这个。
另一方面,如果您希望光标能够离开窗口,并且仅在其位于窗口上方时将其隐藏,则应该处理
WM_SETCURSOR
消息并使用SetCursor
为隐藏光标。From what I understand, your problem is not in hiding the mouse cursor, but in constraining it to your window?
In that case, the
ClipCursor
function should do the job.For a border-less full-screen window, it should be fine to do that once. You would need to repeat that step if your window's position or size ever changes or the window loses focus.
For game programming, there are likely better methods though, such as DirectInput, which provides an exclusive mouse handling mode (tutorials available) and does all that for you on a lower-level basis.
There are some discussions available about the different ways to handle this, for instance this one on the MSDN forums.
If, on the other hand, you want the cursor to be able to leave your window, and only hide it while it's over your window, you should handle the
WM_SETCURSOR
message and useSetCursor
to hide the cursor.