问题描述
我知道要使用哪个功能,但无法正常使用。我使用 SetCursorPos()
唯一的问题是它不会将光标设置为Windows坐标,而是设置为屏幕坐标。我还尝试了 ScreenToClient()
,但是它在道德上没有用。
这是我的代码:
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);
有什么想法吗?
我正在使用win32。希望我能提供足够的信息。
any idea?I'm using win32. I hope that I given enough information.
推荐答案
您正在稍微退步。 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 function ScreenToClient
does the opposite. What you're looking for is ClientToScreen
例如:
ClientToScreen(hWnd, &pt);
SetCursorPos(pt.x,pt.y);
文档
- http://msdn.microsoft.com/en-us/library/aa931003.aspx
这篇关于C ++ Win32设置光标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!