


In this case I have put the first number as zero and the second number as 15 so the console color will be white as the code for white is 15. 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 ) it is used here to find the size of the console. This is a structure containing all of the console info written anyway (passing NULL causes an access violation). not used but we need to capture this since it will be This is used to reset the carat/cursor to the top left. Get the handle to the current output buffer.

Void ClearConsoleToColors(int ForgC, int BackC) WORD wColor = ((BackC & 0x0F) //header file for windows The code is - void ClearConsoleToColors(int ForgC, int BackC) Now I am going to give the code of ChangeConsoleToColors. Now I am going to give you the code of each color - Name | Value When you run the program you will get the text color in RED. Printf("\n \n \t This text is written in Red Color \n ")

For example I am taking your sample program - #include To use this function you need to call it from your program. SetConsoleTextAttribute(hStdOut, wColor) WColor = (csbi.wAttributes & 0xF0) + (ForgC & 0x0F) Mask out all but the background attribute, and add in the forgournd color If(GetConsoleScreenBufferInfo(hStdOut, &csbi)) HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE) The code of SetColor is - void SetColor(int ForgC) You copy paste these functions code in your program and do the following steps.The code I am giving will not work in some compilers. I am going to give two function SetColor and ChangeConsoleToColors. In today's compilers these functions would not work. Functions like textcolor worked in old compilers like turbo C and Dev C.
