#includevoidConPrint(char*CharBuffer,intlen);
voidConPrintAt(intx,inty,char*CharBuffer,intlen);
voidgotoXY(intx,inty);
voidClearConsole(void);
voidClearConsoleToColors(intForgC,intBackC);
voidSetColorAndBackground(intForgC,intBackC);
voidSetColor(intForgC);
voidHideTheCursor(void);
voidShowTheCursor(void);
intmain(intargc,char*argv[])
{inti=0,j=0;
HideTheCursor();
ClearConsoleToColors(15,2);
for(i=0;i<8;i++)
for(j=0;j<8;j++)
{if(i%2==0)
{if(j%2==0)
{SetColorAndBackground(15,15);
ConPrintAt(i,j,"\n",1);}
else
{SetColorAndBackground(1,16);
ConPrintAt(i,j,"\n",1);} //红色为重点
}
else
{if(j%2!=0)
{SetColorAndBackground(15,15);
ConPrintAt(i,j,"\n",1);}
else
{SetColorAndBackground(1,16);
ConPrintAt(i,j,"\n",1);}
}
}
SetColorAndBackground(7,1);
return0;
}
voidClearConsoleToColors(intForgC,intBackC)
{
WORDwColor=((BackC&0x0F)<<4)+(ForgC&0x0F);
HANDLEhStdOut=GetStdHandle(STD_OUTPUT_HANDLE);
COORDcoord={0,0};
DWORDcount;
CONSOLE_SCREEN_BUFFER_INFOcsbi;
SetConsoleTextAttribute(hStdOut,wColor);
if(GetConsoleScreenBufferInfo(hStdOut,&csbi))
{
FillConsoleOutputCharacter(hStdOut,(TCHAR)32,csbi.dwSize.X*csbi.dwSize.Y,coord,&count);
FillConsoleOutputAttribute(hStdOut,csbi.wAttributes,csbi.dwSize.X*csbi.dwSize.Y,coord,&count);
SetConsoleCursorPosition(hStdOut,coord);
}
}
voidClearConsole()
{
HANDLEhStdOut=GetStdHandle(STD_OUTPUT_HANDLE);
COORDcoord={0,0};
DWORDcount;
CONSOLE_SCREEN_BUFFER_INFOcsbi;
if(GetConsoleScreenBufferInfo(hStdOut,&csbi))
{
FillConsoleOutputCharacter(hStdOut,(TCHAR)32,csbi.dwSize.X*csbi.dwSize.Y,coord,&count);
FillConsoleOutputAttribute(hStdOut,csbi.wAttributes,csbi.dwSize.X*csbi.dwSize.Y,coord,&count);
SetConsoleCursorPosition(hStdOut,coord);
}
}
voidgotoXY(intx,inty)
{
COORDcoord={x,y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),coord);
}
voidSetColor(intForgC)
{
WORDwColor;
HANDLEhStdOut=GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFOcsbi;
if(GetConsoleScreenBufferInfo(hStdOut,&csbi))
{
wColor=(csbi.wAttributes&0xF0)+(ForgC&0x0F);
SetConsoleTextAttribute(hStdOut,wColor);
}
}
voidSetColorAndBackground(intForgC,intBackC)
{
WORDwColor=((BackC&0x0F)<<4)+(ForgC&0x0F);;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),wColor);
}
voidConPrint(char*CharBuffer,intlen)
{
DWORDcount;
WriteConsole(GetStdHandle(STD_OUTPUT_HANDLE),CharBuffer,len,&count,NULL);
}
voidConPrintAt(intx,inty,char*CharBuffer,intlen)
{
DWORDcount;
COORDcoord={x,y};
HANDLEhStdOut=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hStdOut,coord);
WriteConsole(hStdOut,CharBuffer,len,&count,NULL);
}
voidHideTheCursor()
{
CONSOLE_CURSOR_INFOcciCursor;
HANDLEhStdOut=GetStdHandle(STD_OUTPUT_HANDLE);
if(GetConsoleCursorInfo(hStdOut,&cciCursor))
{
cciCursor.bVisible=FALSE;
SetConsoleCursorInfo(hStdOut,&cciCursor);
}
}
voidShowTheCursor()
{
CONSOLE_CURSOR_INFOcciCursor;
HANDLEhStdOut=GetStdHandle(STD_OUTPUT_HANDLE);
if(GetConsoleCursorInfo(hStdOut,&cciCursor))
{
cciCursor.bVisible=TRUE;
SetConsoleCursorInfo(hStdOut,&cciCursor);
}
}