If you have any queries regarding the source code, bring them up to me from the comments section. With this post, I hope you learnt how to change console windows background color in CodeBlocks without using graphics. 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). Here’s an output screen of what happened in the console window. SetConsoleCursorPosition(hStdOut, coord) This will set our cursor position for the next print statement This fills the buffer with a given character (in this case 32=space).įillConsoleOutputCharacter(hStdOut, (TCHAR) 32, *, coord, &count) įillConsoleOutputAttribute(hStdOut, csbi.wAttributes, *, coord, &count ) If(GetConsoleScreenBufferInfo(hStdOut, &csbi)) SetConsoleTextAttribute(hStdOut, wColor) Now the current color will be set by this handle It is used here to find the size of the console. This is a structure containing all the console info written anyway (passing NULL causes an access violation). It is not used but we need to capture this since it will be This is a return value indicating how many characterss were written This is used to reset the carat/cursor to the top left. HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE) This is used to get the handle to current output buffer. WP Dark Mode supports all major operating systems including. Just activate dark mode on your device, and browse the website to experience a magically transformed dark mode of your website. Void ClearConsoleToColors(int ForgC, int BackC) This dark mode plugin intelligently detects device preferences and dynamically delivers a handcrafted, expert-designed dark mode experience for your readers. Void ClearConsoleToColors(int ForgC, int BackC) //function declarationĬlearConsoleToColors(10,4) //function call to change console background color #include //C standard library header file #include //This is the windows header file How to Change Console Windows Background Color in CodeBlocks Without using this function, the background color in console would’ve been default black. 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. Source Code:Ĭurrently the console window background color displayed is Red color. 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. 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 code is written in C language, and I have included comments in the code to help you understand it better. To change the console window background color, simply copy the source code provided here, and compile it in Code::Blocks IDE. This is pretty simple if you’ve already gone through my previous posts. In this tutorial, I will take you through “How to Change Console Windows Background Color in CodeBlocks”. In my earlier tutorials, I took you through how to change text color and text background color in Code::Blocks.
0 Comments
Leave a Reply. |