1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
#include <windows.h>
enum
{
black,
dark_blue,
dark_green,
dark_cyan,
dark_red,
dark_magenta,
dark_yellow,
light_gray,
dark_gray,
light_blue,
light_green,
light_cyan,
light_red,
light_magenta,
light_yellow,
white
};
int getcolors()
{
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(
GetStdHandle( STD_OUTPUT_HANDLE ),
&csbi
);
return csbi.wAttributes;
}
int getfgcolor()
{
return getcolors() & 0x0F;
}
int getbgcolor()
{
return getcolors() >> 4;
}
void setfgcolor( int color )
{
SetConsoleTextAttribute(
GetStdHandle( STD_OUTPUT_HANDLE ),
(getcolors() & 0xF0) | (color & 0x0F)
);
}
void setbgcolor( int color )
{
SetConsoleTextAttribute(
GetStdHandle( STD_OUTPUT_HANDLE ),
((color & 0x0F) << 4) | (getcolors() & 0x0F)
);
}
void setcolors( int fg, int bg )
{
SetConsoleTextAttribute(
GetStdHandle( STD_OUTPUT_HANDLE ),
((bg & 0x0F) << 4) | (fg & 0x0F)
);
}
|