开发者

How to print mouse coordinates in VC++ Win32 application?

开发者 https://www.devze.com 2023-02-09 01:16 出处:网络
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++

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!

0

精彩评论

暂无评论...
验证码 换一张
取 消