【问题标题】:unknown type INPUT - windows.h未知类型输入 - windows.h
【发布时间】:2018-03-27 10:07:46
【问题描述】:

我最近一直在试验 windows.h 库,编译器找不到我使用的一些类型和函数。

#include <windows.h>
#include <stdio.h>
#include <stdlib.h>

void moveUp(int with) {
    POINT pos;
    if (!GetCursorPos(&pos)) {
        puts("Unable to get cursor position\n");
        exit(-1);
    }
    if (!SetCursorPos(pos.x, pos.y - with)) {
        puts("Unable to move cursor\n");
        exit(-1);
    }
    puts("Success");
}

int getScreenHeight() {
    return GetSystemMetrics(SM_CYSCREEN);
}

void click(int x, int y) {
    INPUT myInput;
    myInput.type = INPUT_MOUSE;
    MOUSEINPUT mouseStruct;
    mouseStruct.dx = x;
    mouseStruct.dy = y;
    mouseStruct.dwFlags = MOUSEEVENTF_XDOWN;
    mouseStruct.mouseData = XBUTTON1;
    mouseStruct.time = 0;
    mouseStruct.dwExtraInfo = NULL;
    myInput.mi = mouseStruct;
    SendInput(1,&myInput,sizeof(INPUT));
}

void startMenu() {
    int height = getScreenHeight();
    if(!SetCursorPos(20,height + 20)){
        puts("Unable to move cursor\n");
        exit(-1);
    }
    click();
}

int main(){
   moveUp(200);
   startMenu();
   return 0;
 }

我在标题中得到了上面的错误,尽管如你所见,windows.h 被包括在内。我怎么能解决这个问题?或者是否需要不同的标头才能使用这些标头?

【问题讨论】:

标签: c windows input


【解决方案1】:

INPUT 仅在 Windows >= 2000 之后才受支持。

因此,您需要define WINVER and/or _WIN32_WINNT 才能使用它。也请阅读Using the Windows Headers

【讨论】:

    猜你喜欢
    • 2013-01-01
    • 1970-01-01
    • 2020-06-10
    • 2016-11-28
    • 1970-01-01
    • 2021-05-26
    • 1970-01-01
    • 1970-01-01
    • 2022-01-09
    相关资源
    最近更新 更多