可以定義新的顏色,並用它作爲存在者
#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");
}
首先,如果你有一個問題關於構建錯誤,那麼請包括他們的問題*未經編輯的*和*完整*。其次,不要在一個問題中提出兩個不相關的問題。 –
對於'睡眠',請參閱http://social.msdn.microsoft.com/Forums/vstudio/en-US/70d6b00b-9708-4d94-893f-0f3ae7b3ef20/sleepint – lurker