应用程序窗口中的光标类型不正确
在尝试使用 Windows API 制作 GUI 之后,我最近意识到了光标的问题。当我编译并运行我的应用程序时,它会显示一个像预期的窗口。当我将光标从屏幕左侧拖动到应用程序窗口时,当它越过边框时,它会变成 <->调整大小的东西,但它仍然像我窗口内的任何地方一样。如果我把它从底部带入窗口,情况也是如此。但当我从右侧这样做时,问题就不存在。我怀疑这是否只是我的程序,所以我去了 MSDN 网站,甚至编译并尝试了他们的程序(http://msdn.microsoft.com/en-us/library/ff381409%28v=VS.85%29.aspx )。同样的问题!于是我开始尝试 WM_SETCURSOR 消息和游标函数,但一无所获。 有人对此有任何解释以及我可以做些什么来解决它吗?任何帮助将不胜感激。
After messing around a little with making a GUI with the Windows API, I recently realized a problem with the cursor. When I compile and run my application, it shows a window like its supposed to. When I drag my cursor from the left side of my screen into my applications window, as it goes over the border it becomes the <-> thing for resizing but it remains like that anywhere inside my window. Same goes for if I bring it into the window from the bottom. The problem does not exist when I do from the right side though. I questioned if it was just my program so I went to the MSDN website and even compiled and tried their program (http://msdn.microsoft.com/en-us/library/ff381409%28v=VS.85%29.aspx). Same Problem! So then I started experimenting with the WM_SETCURSOR message and cursor functions but got nowhere.
Does anyone have any explanation to this and what I could do to fix it? Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,该示例代码的行为正如您所描述的,因为
WNDCLASS
的hCursor
成员设置为零,并且WindowProc()
不处理WM_SETCURSOR
。如果您想要始终使用相同的光标,那么在设置窗口类时最简单的做法是:
如果您想对光标有更多控制,那么您需要离开
WNDCLASS::hCursor
零并调用SetCursor()
来响应WM_SETCURSOR
。您需要加载/创建各种光标,并通过某种方式根据应用程序的状态选择合适的光标。Yes, that example code will behave as you describe because the
hCursor
member ofWNDCLASS
is set to zero, andWindowProc()
doesn't handleWM_SETCURSOR
.If you want the same cursor all the time then it's easiest to do something like this when setting up your window class:
If you want to have more control over the cursor then you want to leave
WNDCLASS::hCursor
zero and callSetCursor()
in response toWM_SETCURSOR
. You'll need to load/create your various cursors, and have some way of choosing the appropriate one based on your application's state.