c语言 多窗口显示文本
发布网友
发布时间:2022-04-23 05:32
我来回答
共1个回答
热心网友
时间:2023-10-04 09:48
输入1-7中任一数字,相应颜色窗口跳出,ESC 退出
#include"conio.h"
#include"stdio.h"
#include"stdlib.h"
void drawb(int index);
void FillBox(int x1, int y1, int x2, int y2, int Color, int BkColor);
void FillBox(int x1, int y1, int x2, int y2, int Color, int BkColor)
{
window(x1,y1,x2,y2);
textattr(Color+(BkColor<<4));
clrscr();
window(1,1,80,25);
}
void drawb(int index)
{
int i, m, n;
char *s[]={"BLACK", "BLUE", "GREEN", "CYAN", "RED", "MAGENTA", "BROWN", "LIGHTGRAY"};
m = (index == 0) ? 1 : index;
n = (index == 0) ? 7 : index;
for (i = m; i <= n; i++)
{
FillBox(5 + i * 4, 4 + i, 40 + i * 4, 6 + i + 5, i - 1, i);
gotoxy(5 + i * 4, 4 + i);
textcolor(i + 7);
textbackground(i);
cprintf("%s", s[i]);
}
}
int main(void)
{
int a;
drawb(0);
while(1)
{
a = getch();
if (a == 27)
return 0;
else if (a >= 49 && a <= 55)
drawb(a - 48);
}
}