1. Change the color of the entire Console
Use System ("color 0a ");
The value 0 after the color is the background color code, and the value a is the foreground color code. The color code is as follows:
0 = black
1 = blue
2 = green
3 = lake blue
4 = red
5 = purple
6 = yellow
7 = white
8 = gray
9 = light blue
A = light green
B = light green
C = light red
D = lavender
E = pale yellow
F = bright white
2. Change the color of the next output or input font and background.
Use the setconsoletextattribute function, as shown in figure
White on black:
Setconsoletextattribute (getstdhandle (std_output_handle), foreground_intensity |
Foreground_red | foreground_green | foreground_blue );
Red on Black:
Setconsoletextattribute (getstdhandle (std_output_handle), foreground_intensity |
Foreground_red );
Green on Black:
Setconsoletextattribute (getstdhandle (std_output_handle), foreground_intensity |
Foreground_green );
Yellow on Black:
Setconsoletextattribute (getstdhandle (std_output_handle), foreground_intensity |
Foreground_red | foreground_green );
Blue on Black:
Setconsoletextattribute (getstdhandle (std_output_handle), foreground_intensity |
Foreground_blue );
Magenta on Black:
Setconsoletextattribute (getstdhandle (std_output_handle), foreground_intensity |
Foreground_red | foreground_blue );
Cyan on Black:
Setconsoletextattribute (getstdhandle (std_output_handle), foreground_intensity |
Foreground_green | foreground_blue );
Black on Gray:
Setconsoletextattribute (getstdhandle (std_output_handle), background_intensity |
Background_intensity );
Black on white:
Setconsoletextattribute (getstdhandle (std_output_handle), background_intensity |
Foreground_intensity | background_red | background_green | background_blue );
Red on White:
Setconsoletextattribute (getstdhandle (std_output_handle), background_intensity |
Foreground_intensity | background_red | background_green | background_blue |
Foreground_red );
And so on.
Header files need to be introduced:
Windows. h
Function prototype:
Bool setconsoletextattribute (handle hconsoleoutput, word wattributes );
The value of wattributes corresponds to the following:
Attributemeaning
Foreground_bluetext color contains blue.
Foreground_greentext color contains green.
Foreground_redtext color contains red.
Foreground_intensitytext color is intensified.
Background_bluebackground color contains blue.
Background_greenbackground color contains green.
Background_redbackground color contains red.
Background_intensitybackground color is intensified.
Common_lvb_leading_byteleading byte.
Common_lvb_trailing_bytetrailing byte.
Common_lvb_grid_horizontaltop horizontal.
Common_lvb_grid_lverticalleft vertical.
Common_lvb_grid_rverticalright vertical.
Common_lvb_reverse_videoreverse foreground and background attributes.
Common_lvb_underscoreunderscore.
Set the font and background color when the console outputs