问题
Normally colors are called through their hexadecimal associations, but in the code is it possible to call these colors trough some constants build in windows console API ?
Here are colors names I found while searching SO: https://stackoverflow.com/a/7138277/393087
colors codes:
7 => default
0 => black
1 => blue
2 => green
3 => aqua
4 => red
5 => purple
6 => yellow
7 => light gray
8 => gray
9 => light blue
A => light green
B => light aqua
C => light red
D => light purple
E => light yellow
F => white
Are these names official ? So for example I could do:
SetConsoleTextAttribute(hConsole,LIGHT_BLUE * 16 + LIGHT_AQUA);
回答1:
Console Screen Buffers - Character Attributes
FOREGROUND_BLUE Text color contains blue.
FOREGROUND_GREEN Text color contains green.
FOREGROUND_RED Text color contains red.
FOREGROUND_INTENSITY Text color is intensified.
BACKGROUND_BLUE Background color contains blue.
BACKGROUND_GREEN Background color contains green.
BACKGROUND_RED Background color contains red.
BACKGROUND_INTENSITY Background color is intensified.
回答2:
Here is complete list of Background and Foreground colors in WinAPI.
/*Enum to store Foreground colors*/
typedef enum FG_COLORS
{
FG_BLACK = 0,
FG_BLUE = 1,
FG_GREEN = 2,
FG_CYAN = 3,
FG_RED = 4,
FG_MAGENTA = 5,
FG_BROWN = 6,
FG_LIGHTGRAY = 7,
FG_GRAY = 8,
FG_LIGHTBLUE = 9,
FG_LIGHTGREEN = 10,
FG_LIGHTCYAN = 11,
FG_LIGHTRED = 12,
FG_LIGHTMAGENTA = 13,
FG_YELLOW = 14,
FG_WHITE = 15
}FG_COLORS;
/*Enum to store Background colors*/
typedef enum BG_COLORS
{
BG_NAVYBLUE = 16,
BG_GREEN = 32,
BG_TEAL = 48,
BG_MAROON = 64,
BG_PURPLE = 80,
BG_OLIVE = 96,
BG_SILVER = 112,
BG_GRAY = 128,
BG_BLUE = 144,
BG_LIME = 160,
BG_CYAN = 176,
BG_RED = 192,
BG_MAGENTA = 208,
BG_YELLOW = 224,
BG_WHITE = 240
}BG_COLORS;
来源:https://stackoverflow.com/questions/8621578/do-windows-console-color-values-have-official-names-constants-associated-with