PeekMessage() 重置鼠标光标

发布于 2024-08-13 14:56:56 字数 862 浏览 3 评论 0原文

我目前正在尝试在 Windows XP 的 C++ 应用程序之类的游戏中更改鼠标光标。

要更改光标,我使用 SetCursor() 并传入所需的光标,该光标正在工作。然而,在调用 PeekMessage() 的 while 循环期间,光标不断重置回默认箭头。

这是有问题的循环:

MSG  msg;
while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
    TranslateMessage( &msg );
    DispatchMessage( &msg );
}

在调试时,我发现光标在调用 PeekMessage() 期间发生了变化,之后 msg.message == 0x200,这应该使消息成为以下之一:

WM_MOUSEFIRST = 0x200
WM_MOUSEMOVE = 0x200

我没有能够找到有关为什么会发生这种情况的任何信息,并且没有使用 Windows 消息的经验。

谢谢。

编辑:

根据此处< /a> 每次鼠标移动时,系统都会重新绘制类光标,从而有效地将其设置回默认光标。考虑到这一点,我将其添加到窗口消息回调函数中:

case WM_SETCURSOR:
    return 0;

问题解决了。

Im currently messing around with changing the mouse cursor within a game like C++ application for Windows XP.

To change the cursor I am using SetCursor() and passing in the desired cursor, which is working. However during the while loop in which PeekMessage() is called the cursor keep getting reset back to the default arrow.

This is the offending loop:

MSG  msg;
while( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
    TranslateMessage( &msg );
    DispatchMessage( &msg );
}

While debugging I found that the cursor changed during the call to PeekMessage() after which msg.message == 0x200, which should make the message one of these:

WM_MOUSEFIRST = 0x200
WM_MOUSEMOVE = 0x200

I haven't been able to find any information on why this is happening, and have no experience with windows messages.

Thanks.

Edit:

According to here the system redraws the class cursor everytime the mouse moves, effectively setting it back to the default cursor. With this in mind i added this to the window message callback function:

case WM_SETCURSOR:
    return 0;

problem solved.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瑾夏年华 2024-08-20 14:56:56

你是如何调试的?除非您使用 SoftIce 或其他不共享 Windows 鼠标指针的应用程序,否则很难将调试器与应用程序隔离。

How did you debug that? Unless you use SoftIce or some other application which doesn't share the windows mouse pointer, it would be hard to isolate the debugger from the application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文