How to Highlight or Change Text Background Color in CodeBlocks Console Window?


Here’s a tutorial┬áthat will guide you through “How to highlight or change text background color in CodeBlocks Console Window”. The source code provided here will change text background color or highlight the text in the console window of Code::Blocks without using graphics. You can simply copy the code, and compile it in Code::Blocks IDE. The source 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 SetColorAndBackground (int ForgC, int BackC) takes two integer values, and is responsible for the change in text background color in the console window.

Source Code:

Currently the text background color displayed is Red color. You can change your desired text color by passing integer values (in the range of 0 to 256) in the SetColorAndBackground (int ForgC, int BackC) function. The source code is short; compile it in Code::Blocks, not Turbo C.

Here’s an output screen of what happened in the console window. As you can see, previously the text color was white and the background color was black. But after the function call with integer values (10,4) in the function SetColorAndBackground (int ForgC, int BackC), the text background was highlighted in red, i.e, its background color changed to red.

How to highlight or change text background color in CodeBlocks Console Window

With this post, I hope you learnt how to highlight or change text background color in CodeBlocks console window. Also see, how to change text color and console window background color in Code::Blocks. If you have any queries, bring them up to me from the comments box below.


Please enter your comment!
Please enter your name here