c++ win32设置光标位置
我知道要使用哪个功能,但我无法让它正常工作。我使用了SetCursorPos()
,唯一的问题是它将光标设置为屏幕坐标而不是窗口坐标。我还尝试了 ScreenToClient()
但它不起作用。
这是我的代码:
pt.x=113;
pt.y=280;
ScreenToClient(hWnd, &pt);
SetCursorPos(pt.x, pt.y);
有什么想法吗? 我用的是win32。我希望我提供了足够的信息。
I know which function to use but I can't get it to work right. I used SetCursorPos()
the only problem is that it sets the cursor not to the windows coordinates but to the screen coordinates. i also tried the ScreenToClient()
but it didn't work ethier.
Here is my code:
pt.x=113;
pt.y=280;
ScreenToClient(hWnd, &pt);
SetCursorPos(pt.x, pt.y);
any idea?
I'm using win32. I hope that I given enough information.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的做法有点倒退了。
SetCursorPos
函数在屏幕坐标中工作,并且您希望根据窗口/客户端坐标设置光标。为此,您需要从客户端映射到屏幕坐标。函数ScreenToClient
执行相反的操作。您正在寻找的是ClientToScreen
例如:
文档
You're approaching this slightly backwards. The
SetCursorPos
function works in screen cordinates and you want to set the cursor based on window / client coordinates. In order to do this you need to map from client to screen coordinates. The functionScreenToClient
does the opposite. What you're looking for isClientToScreen
For example:
Documentation