How to print mouse coordinates in VC++ Win32 application?
I know ther开发者_高级运维e is a function GetCursorPos
and the WM_MOUSEMOVE
event but can anybody tell me with example code how best to print the mouse coordinates? I'm not sure how to do this in VC++.
Try this and let me know .
POINT coord;
GetCursorPos(&coord);
cout << "The mouse is at:" << coord.x << coord.y << endl;
As you've mentioned, you can get the instantaneous position of the mouse cursor on the screen using GetCursorPos
. Here's a sample:
POINT pt;
if (!GetCursorPos(&pt)) {
/* ... handle the error ... */
}
You'll need to #include <windows.h>
to use this code. Once you have called the function, you can read the mouse coordinates from pt.x
and pt.y
.
Hope this helps!
精彩评论