Jump to content
  • Advertisement
Sign in to follow this  
Funkyjive

Windows SetCursorPos() relative problem (RESOLVED)

This topic is 3284 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!