Saturday, March 19, 2011

Text background color of console windows using C in code::block

use this source code to change text background color of console windows in code::block
source code download here.
#include <windows.h>
#include <stdio.h>
void SetColorAndBackground(int ForgC, int BackC);
int main()
    SetColorAndBackground(5,1);   //color value range 0 up-to 256
    printf("what is text background color");
    return 0;
void SetColorAndBackground(int ForgC, int BackC)
     WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);;
     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);


  1. Finally, code involving colours that actually works! And not for Borland compilers. Thank you so much.

  2. how can i copy this code directly and paste into turbo c ??
    because it cant paste over there