如题。
下面是代码
#include <stdio.h>
#include <iostream>
#include <Windows.h>
#include <Mmsystem.h>
#include <joystickapi.h>
//#include <myjoy.h>
#pragma comment(lib, "WinMM.lib")
int main() {
UINT num,IF;
BOOL ID;
int i;
JOYINFO joyinfo;
/*struct joyinfo_tag {
UINT wXpos;
UINT wYpos;
UINT wZpos;
UINT wButtons;
} JOYINFO, * PJOYINFO, * NPJOYINFO, * LPJOYINFO;*/
//joyGetPos(JOYSTICKID1, &joyinfo);
//IF = JOY_BUTTON1;
//JOYINFO joyinfo;
num = joyGetNumDevs();
printf("%u\n", num);
Sleep(1000);
ID = joyGetPos(JOYSTICKID1, &joyinfo);
if (ID == JOYERR_NOERROR) {
printf("Have a joy\n");
Sleep(1000);
}
else {
printf("the joy is null\n");
Sleep(1000);
}
typedef struct alphe{};
//listen();
//printf("%u", IF);
for (;;) {
/*joyGetPos(JOYSTICKID1, &joyinfo);
IF = JOY_BUTTON1;
if (IF == 0) {
printf("the button1 is down\n");
Sleep(1000);
}
else {
printf("the button1 is not down\n");
Sleep(1000);
}*/
if (num > 0)
{
//joySetThreshold(JOYSTICKID1, 10000);
//joySetCapture((HWND)this->winId(), JOYSTICKID1, NULL, TRUE);
IF = joyinfo_tag.wButtons;
if (IF == JOY_BUTTON1) {
printf("the Button1 is down\n");
}
else if (IF == JOY_BUTTON2) {
printf("the Button2 is down\n");
}
}
}
}
然后在第56行 IF = joyinfo_tag.wButtons; 这个赋值语句中的结构体 joyinfo_tag 被vc++说成“不允许使用类型名”
下面是图片:
![img](
https://img-mid.csdnimg.cn/release/static/image/mid/ask/387627892826128.png
https://img-mid.csdnimg.cn/release/static/image/mid/ask/387627892826128.png
'无标题.png‘
希望各位能多多帮助
(与joystick有关,需要头文件请私信)