Wednesday 8 January 2014

Changing color of output window in Visual C++

Okay. Have you ever wondered how it would be to try something different than the same old black and white output window? Then this post is just for you.

For this, you will have to use the Visual C++ IDE [ :'( ]. Here are the steps:

1.You must add the header <windows.h>
2. The statement to change the color is :
system("color <color_code>");
 Color code is a couple of hexadecimal numbers, the first one corresponding to background color and the second one to font color.
Here is a simple example:

    #include<windows.h>
    void main()
    {
        system("color 95");
    }
This program renders the background color of output window as blue and font color as purple!


You can try different hexadecimal numbers instead of numbers to change the color according to your will. Here is the list of numbers and corresponding colors:

0 = Black                                    8 = Gray
1 = Blue                                      9 = Light Blue
2 = Green                                   A = Light Green
3 = Aqua                                    B = Light Aqua
4 = Red                                      C = Light Red
5 = Purple                                   D = Light Purple
6 =  Yellow                                  E = Light Yellow
7 = White                                    F = Bright White

e.g., If you want a Light Green background with Blue font in it, the statement should be
system("color A1");
You could play around with this command and have lots of fun with it!

NOTE : "color" is not to be confused with "colour" because former is American spelling and latter is British. Most of the programming and scripting languages use American spelling.

That's all for today folks.... Later!


You might also like