Pages

Saturday, 23 April 2016

Text Background Color of Console Windows using C

use this source code to change text background color of console windows in code::block


#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");
     Sleep(1000);
     return 0;
}
void SetColorAndBackground(int ForgC, int BackC){
     WORD wColor = ((BackC & 0x0F) << 4) + (ForgC & 0x0F);;
     SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), wColor);
     return;
}

No comments:

Post a Comment