Codeblocks Set Color

You might also like

You are on page 1of 1

#include<stdio.h> #include<windows.

h> //before you can set the color in cmd you must include a windows library void SetColor(int color); //This function declaration should be included!! main()//sample program { int x; for(x=0;x<37;x++) { SetColor(x); //Format:in your codes type SetColor(any number); printf("Color %d\n",x); } } void SetColor(int color)//Include this function definition!! { WORD wColor; HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO csbi; if(GetConsoleScreenBufferInfo(hStdOut, &csbi)) { wColor = (csbi.wAttributes & 0xF0) + (color & 0x0F); SetConsoleTextAttribute(hStdOut, wColor); } return; }

You might also like