光标样式不保持更新

发布于 2024-10-08 09:11:45 字数 227 浏览 3 评论 0原文

我有一个普通的 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 技术交流群。

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

发布评论

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

评论(2

尐籹人 2024-10-15 09:11:45

注册窗口类时设置有效的光标句柄。请参阅 WNDCLASSEX::hCursor 。使用LoadCursor加载有效的光标。喜欢,

WNDCLASSEX wc = {0};
...
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
...
RegisterClassEx(&wc);

Set a valid cursor handle when you register your window class. See WNDCLASSEX::hCursor. Use LoadCursor to load a valid cursor. Like,

WNDCLASSEX wc = {0};
...
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
...
RegisterClassEx(&wc);
忘羡 2024-10-15 09:11:45

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 the hCursor field in the WNDCLASS 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 calls SetCursor with whatever cursor is appropriate and then returns TRUE.

See SetCursor for details.

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