C 语言 Windows API 获取当前鼠标位置

// 函数定义
#include <windows.h>

void get_pos(int *x, int *y) {
    POINT point;
    GetCursorPos(&point);
    *x = point.x;
    *y = point.y;
}
// 测试用例
#include <stdio.h>
#include <windows.h>

void get_pos(int *x, int *y) {
    POINT point;
    GetCursorPos(&point);
    *x = point.x;
    *y = point.y;
}

int main(void) {
    int x, y;
    Sleep(1000); // 等待一秒
    get_pos(&x, &y);
    printf("Position: (%d, %d)\n", x, y);
    return 0;
}

posted on 2022-03-18 11:04  UXOD  阅读(302)  评论(0编辑  收藏  举报