您可以定义新颜色并将其用作现有颜色
#define FOREGROUND_WHITE (FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN)
下面的代码将
根据结果打印前景色和背景色的不同组合,并根据需要传递值。
for(i=0; i<255; i++)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), i);
printf("NEW COLOUR=%d\n",i);
}
编辑
#include<stdio.h>
#include<windows.h>
/*
//0-black
//1-blue
//2-green
// ......
//15-white
//0-15-black back ground, text colour as above 0-black,15-white
//16-31blue back ground, text colour as above 16+0 -black 16+15-white
//32-47green back ground, text colour as above 32+0 -black 32+15-white
// ......
//240-white back ground, text colour as above 240+0 -black 240+15-white
*/
int main()
{
int i;
for(i=0; i<256; i++) //loop to print text colours 0-15 total 16 colours
{
// Sleep( 3000 ); // sleep three seconds
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), i);
printf("Text colour=%d\n",i);
}
system("pause");
for(i=0; i<256; i=i+8) //background colours 0-15 total 16 back grounds
{
// Sleep( 3000 ); // sleep three seconds
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), i);
printf("Back ground=%d\n",i);
}
system("pause");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0+15); //white text +black background
system("pause");
}