Set the font and background color when the console outputs

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.