c++ win32 set cursor position

后端 未结 1 796
小鲜肉
小鲜肉 2021-02-10 18:40

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

1条回答
  •  旧巷少年郎
    2021-02-10 19:30

    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

    0 讨论(0)
提交回复
热议问题