c++ win32 set cursor position

18,500

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

Share:
18,500
Ramilol
Author by

Ramilol

Im 13 years old :-). Im web developer just getting started with c++. A lot of people suggested me to learn c before c++ but i thought of learning both at the same time ;). I know css, javascript, html, php, and sql. Im working in my new game, Xstrike. Im planing to make a monoploy game using directx. After im done, im going to learn c# or java.

Updated on June 09, 2022

Comments

  • Ramilol
    Ramilol almost 2 years

    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.