2015-04-21 10:54:43
#include <windows.h>
#include <iostream>
using namespace std;
#define Color_count 15 //void SetColor(unsigned short ForeColor = 3, unsigned short BackgroundColor = 0)
void SetColor(int color)
{
if(color < || color >= )
return; static WORD WinColorFG[Color_count] =
{
, // BLACK
FOREGROUND_RED, // RED
FOREGROUND_GREEN, // GREEN
FOREGROUND_RED | FOREGROUND_GREEN, // BROWN
FOREGROUND_BLUE, // BLUE
FOREGROUND_RED |FOREGROUND_BLUE, // MAGENTA
FOREGROUND_GREEN | FOREGROUND_BLUE, // CYAN
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE,// WHITE
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY,// YELLOW
FOREGROUND_RED | FOREGROUND_INTENSITY, // RED_BOLD
FOREGROUND_GREEN | FOREGROUND_INTENSITY, // GREEN_BOLD
FOREGROUND_BLUE | FOREGROUND_INTENSITY, // BLUE_BOLD
FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY,// MAGENTA_BOLD
FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY,// CYAN_BOLD
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY // WHITE_BOLD
};
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, WinColorFG[color]);
/*SetConsoleTextAttribute(hConsole, ForeColor | BackgroundColor);*/
} int main()
{
for(int i = ; i < ; ++i)
{
SetColor(i);
cout<<"Hello World!"<<endl;
}
/*SetColor();
cout<<"Hello World!"<<endl;
SetColor(FOREGROUND_RED);
cout<<"Hello World!"<<endl;
cout<<"Hello World!"<<endl;*/
system("pause");
return ;
}