Sign in to follow this  
Funkyjive

Windows SetCursorPos() relative problem (RESOLVED)

Recommended Posts

Hello again. This time I come with a windows API problem. What I am wanting to do is set the position of the cursor to the center of my client window. Looking through the MSDN documentation the SetCursorPos() function is what I am looking for. The problem is that the position specified for the parameters are not relative to the client window but the entire screen. How would I go about getting the position of the upper corner of my client window so I could calculate the center of the client window from there? Thanks! [Edited by - Funkyjive on June 21, 2009 7:46:34 PM]

Share this post


Link to post
Share on other sites
Just get your cursor position and run it through ScreenToClient


POINT mouse;
GetCursorPos(&mouse);
ScreenToClient(hWndMain,&mouse); //stores our on screen mouse coordinates

Share this post


Link to post
Share on other sites
Im not sure I understand the logic there? I already can get the location of my mouse in the client window what I want to do is be able to SET it's position in client coordinates.

Share this post


Link to post
Share on other sites
Thank you. For anyone who stumbles across this question in the future here is what now works for me...

SetPosition(int x, int y)
{
POINT pt;
pt.x = x;
pt.y = y;
ClientToScreen(window, &pt);
SetCursorPos(pt.x, pt.y);
}


Thanks for the help SiCrane!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this