Windows SetCursorPos() relative problem (RESOLVED)

Started by
3 comments, last by Funkyjive 14 years, 10 months ago
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]
"I would rather be in the boat with a drink on the rocks, than in the drink with a boat on the rocks" -Unknown
Advertisement
Just get your cursor position and run it through ScreenToClient


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

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.
"I would rather be in the boat with a drink on the rocks, than in the drink with a boat on the rocks" -Unknown
There's also the function ClientToScreen().
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!
"I would rather be in the boat with a drink on the rocks, than in the drink with a boat on the rocks" -Unknown

This topic is closed to new replies.

Advertisement