I want to get the current mouse position of the window, and assign it to 2 variables x
and y
(co-ordinates relative to the window, not to the screen as a whole).
I'm using Win32 and C++.
And a quick bonus question: how would you go about hiding the cursor/unhiding it?
You get the cursor position by calling
GetCursorPos
.This returns the cursor position relative to screen coordinates. Call
ScreenToClient
to map to window coordinates.You hide and show the cursor with
ShowCursor
.You must ensure that every call to hide the cursor is matched by one that shows it again.
GetCursorPos() will return to you the x/y if you pass in a pointer to a POINT structure.
Hiding the cursor can be done with ShowCursor().