通过 Windows API 获取鼠标位置等状态信息


#include <graphics.h>
#include <stdio.h>

void main()
{
    initgraph(640, 480);        // 初始化绘图窗口
    HWND hwnd = GetHWnd();        // 获取绘图窗口句柄

    POINT point;
    TCHAR s[10];

    while(true)
    {
        GetCursorPos(&point);            // 获取鼠标指针位置(屏幕坐标)
        ScreenToClient(hwnd, &point);    // 将鼠标指针位置转换为窗口坐标

        // 获取鼠标按键状态可以用 GetAsyncKeyState 函数,这里不再详述。

        // 输出鼠标坐标
        sprintf(s, _T("%05d"), point.x);
        outtextxy(0, 0, s);

        sprintf(s, _T("%05d"), point.y);
        outtextxy(0, 20, s);

        // 适当延时
        Sleep(10);
    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM