How to Change Console Windows Background Color in CodeBlocks?

0
2702

In my earlier tutorials, I took you through how to change text color and text background color in Code::Blocks. In this tutorial, I will take you through “How to Change Console Windows Background Color in CodeBlocks”. This is pretty simple if you’ve already gone through my previous posts.

To change the console window background color, simply copy the source code provided here, and compile it in Code::Blocks IDE. The code is written in C language, and I have included comments in the code to help you understand it better.

The source code consists of two header files, windows.h, the header file for windows, and stdio.h, the C standard library header file. The function void ClearConsoleToColors (int ForgC, int BackC) takes two integer values, and is responsible for the change in the background color of CodeBlocks console window.

Source Code:

Currently the console window background color displayed is Red color. You can change your desired console windows color by passing integer values (in the range of 0 to 256) in the ClearConsoleToColors (int ForgC, int BackC) function. Without using this function, the background color in console would’ve been default black.

Here’s an output screen of what happened in the console window. As you can see, with the function ClearConsoleToColors (int ForgC, int BackC), the background of the console window¬†changed to red with integer values (10,4).

How to Change Console Windows Background Color in CodeBlocks
With this post, I hope you learnt how to change console windows background color in CodeBlocks without using graphics. If you have any queries regarding the source code, bring them up to me from the comments section.

LEAVE A REPLY

Please enter your comment!
Please enter your name here