c++ win32 set cursor position

夙愿已清 提交于 2019-12-04 14:27:33

问题


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.


回答1:


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

For example:

ClientToScreen(hWnd, &pt);
SetCursorPos(pt.x,pt.y);

Documentation

  • http://msdn.microsoft.com/en-us/library/aa931003.aspx


来源:https://stackoverflow.com/questions/3645281/c-win32-set-cursor-position

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!