繁体   English   中英

如何在VC ++ Win32应用程序中打印鼠标坐标?

[英]How to print mouse coordinates in VC++ Win32 application?

我知道有一个函数GetCursorPosWM_MOUSEMOVE事件,但任何人都可以通过示例代码告诉我如何最好地打印鼠标坐标? 我不确定如何在VC ++中执行此操作。

如前所述,您可以使用GetCursorPos获取鼠标光标在屏幕上的瞬时位置。 这是一个示例:

POINT pt;
if (!GetCursorPos(&pt)) {
    /* ... handle the error ... */
}

您需要#include <windows.h>才能使用此代码。 调用函数后,您可以从pt.xpt.y读取鼠标坐标。

希望这可以帮助!

试试这个,让我知道。

POINT coord;
GetCursorPos(&coord);
cout << "The mouse is at:" << coord.x << coord.y << endl;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM