[英]How to print mouse coordinates in VC++ Win32 application?
I know there is a function GetCursorPos
and the WM_MOUSEMOVE
event but can anybody tell me with example code how best to print the mouse coordinates? 我知道有一个函数
GetCursorPos
和WM_MOUSEMOVE
事件,但任何人都可以通过示例代码告诉我如何最好地打印鼠标坐标? I'm not sure how to do this in VC++. 我不确定如何在VC ++中执行此操作。
As you've mentioned, you can get the instantaneous position of the mouse cursor on the screen using GetCursorPos
. 如前所述,您可以使用
GetCursorPos
获取鼠标光标在屏幕上的瞬时位置。 Here's a sample: 这是一个示例:
POINT pt;
if (!GetCursorPos(&pt)) {
/* ... handle the error ... */
}
You'll need to #include <windows.h>
to use this code. 您需要
#include <windows.h>
才能使用此代码。 Once you have called the function, you can read the mouse coordinates from pt.x
and pt.y
. 调用函数后,您可以从
pt.x
和pt.y
读取鼠标坐标。
Hope this helps! 希望这可以帮助!
Try this and let me know . 试试这个,让我知道。
POINT coord;
GetCursorPos(&coord);
cout << "The mouse is at:" << coord.x << coord.y << endl;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.