• Advertisement

Archived

This topic is now archived and is closed to further replies.

How do you use GetCursorPos

This topic is 6452 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

Advertisement
What's there to wonder about? It's very self-explaining.

The GetCursorPos function retrieves the cursor's position, in screen coordinates.

                
BOOL GetCursorPos(
LPPOINT lpPoint // address of structure for cursor position

);

...

POINT pt;
GetCursorPos(&pt);

...

// Convert to window coordinates (from screen coordinates)
RECT window_rect;
GetWindowRect(g_hwnd, &window_rect);

pt.x -= window_rect.left;
pt.y -= window_rect.top;

...

// Convert to client coordinates (from window coordinates)
RECT client_rect;
GetClientRect(g_hwnd, &client_rect);

pt.x -= client_rect.left;
pt.y -= client_rect.top;



"Paranoia is the belief in a hidden order behind the visible." - Anonymous

Edited by - Staffan on June 25, 2000 5:50:43 PM

Edited by - Staffan on June 25, 2000 5:51:58 PM

Share this post


Link to post
Share on other sites
This is how I normally use it:

int mouse_x;
int mouse_y;
POINT mouse_pos;
GetCursorPos(&mouse_pos);
mouse_x = mouse_pos.x;
mouse_y = mouse_pos.y;

Do you have the MSDN docs? They explain the process quite well...

- Daniel

Share this post


Link to post
Share on other sites

  • Advertisement