1,在控制台的某个地方输出指定字符
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
void gotoxy(int x,int y,char k){
COORD pos ={(short)(y),(short)(x)};//设置坐标
SetConsoleCursorPosition(hOut,pos);
printf("%c",k);
}
或者只移动光标位置:
HANDLE hOut=GetStdHandle(STD_OUTPUT_HANDLE);
void gotoxy2(int x,int y){
COORD pos ={(short)(y),(short)(x)};//设置坐标
SetConsoleCursorPosition(hOut,pos);
}
2,改变字体颜色
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
printf("Snake");
其他各种各样的颜色可以去找找它的写法,网上应该一大堆QAQ
3,鼠标点击
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
INPUT_RECORD mouseRec;
DWORD res;
COORD crPos, crHome = { 0, 0 };
while(1){
ConsoleInput(hIn, &mouseRec, 1, &res);
if (mouseRec.EventType == MOUSE_EVENT) {
crPos = mouseRec.Event.MouseEvent.dwMousePosition;
if (mouseRec.Event.MouseEvent.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED){
//你想写的东西
//这里是单击左键,还有一些其他功能网上有代码
break;
}
}
}
代码都是各个地方搜罗的,非原创()
已经收了很久了忘了最初是从哪里看到的了()