修改如下,供参考:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <windows.h>
void HideCursor() //隐藏光标
{
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO cci;
GetConsoleCursorInfo(hOut, &cci);
cci.bVisible = FALSE;
SetConsoleCursorInfo(hOut, &cci);
}
void GotoXY(int x, int y) //光标移动到x,y位置
{
COORD pos = { x,y };
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);// 获取标准输出设备句柄
SetConsoleCursorPosition(hOut, pos); //两个参数分别是指定哪个窗体,具体位置
}
int main()
{
int x1 = 10, y1 = 1, x2 = x1 + 26 + 2, y2 = y1 + 20;
int i;
char c;
system("mode con cols=50 lines=25");
HideCursor();
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
Rectangle((HDC)hOut, x1, y1, x2, y2);//DrawRectangle(x1, y1, x2, y2);
GotoXY(x1 + 2, y2 - 1);
printf("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
do{
c = rand() % 26 + 'A';
for (i = y1 + 1; i < y2 - 1; i = i + 1)
{
GotoXY(x1 + c - 'A' + 2, i);
printf("%c", c);
Sleep(100);
GotoXY(x1 + c - 'A' + 2, i);
printf(" ");
}
GotoXY(x1 + c - 'A' + 2, i);
printf("=");
Sleep(200);
GotoXY(x1 + c - 'A' + 2, i);
printf("%c", c);
} while (kbhit() == 0);
return 0;
}