光标样式不保持更新
我有一个普通的 Windows GUI 应用程序(使用 API,而不是 MFC 制作),当我在应用程序上移动鼠标时,鼠标会更改样式(例如,当您将其移动到边框上时,它会更改为调整大小箭头等) .) 但有时它会“粘”在那种风格上,这样我就可以移动鼠标,它会停留在调整大小箭头或其他位置,即使它离开了窗口边框。如果我将它移到另一个控件上,它会自行修复。
这只是一个不便,但看起来不专业,我想解决它。我怎样才能使它始终保持最新状态?
I have a normal Windows GUI application (made using the API, not MFC) and as I move my mouse on and off the application and the mouse changes styles (like when you move it over the border, it changes to a resize arrow, etc.) but sometimes it "sticks" in that style, so that I can move the mouse around and it will stay in a resize arrow or whatever, even after it's off the window border. It fixes itself if I move it over another control.
It's just an inconvenience, but it looks unprofessional and I would like to fix it. How can I make it where it stays up to date all the time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
注册窗口类时设置有效的光标句柄。请参阅 WNDCLASSEX::hCursor 。使用
LoadCursor
加载有效的光标。喜欢,Set a valid cursor handle when you register your window class. See
WNDCLASSEX::hCursor
. UseLoadCursor
to load a valid cursor. Like,tenfour的回答是正确的。这里有更多背景知识。
当鼠标在窗口内移动且未被捕获时,窗口将收到
WM_SETCURSOR
消息。消息名称可能有点令人困惑。基本上是窗口设置光标的机会,而不是设置光标的指令。窗口可以通过调用SetCursor并返回来处理此消息。
窗口还可以通过将消息传递给 DefWindowProc 来获取默认行为。默认行为是查看窗口的
WNDCLASS
中的hCursor
字段。这就是 tenfour 的答案有效的原因。(实际上比这更复杂一点,因为 DefWindowProc 首先给父窗口一个干预的机会。)
如果您想做一些动态的事情,比如根据某些状态变量选择光标,那么您应该必须处理
WM_SETCURSOR
,以便它使用任何合适的光标调用SetCursor
,然后返回TRUE
。请参阅
SetCursor
详细信息。tenfour's answer is correct. Here's a little more background.
When the mouse moves within a window, and it's not captured, the window will get a
WM_SETCURSOR
message. The message name can be a little confusing. It's basically the window's opportunity to set the cursor, not an instruction to set the cursor.A window can handle this message by calling
SetCursor
and returning.A window can also punt by passing the message to
DefWindowProc
to get the default behavior. The default behavior is to look at thehCursor
field in theWNDCLASS
for the window. This is why tenfour's answer works.(It's actually a bit more complicated than that, since the
DefWindowProc
first gives the parent window a chance to intervene.)If you want to do something dynamic, like choose a cursor depending on some state variable, then you should have to handle the
WM_SETCURSOR
so that it callsSetCursor
with whatever cursor is appropriate and then returnsTRUE
.See
SetCursor
for details.