PeekMessage() 重置鼠标光标
我目前正在尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你是如何调试的?除非您使用 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.