Created
November 5, 2013 10:25
-
-
Save Codeplaza/7316954 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> //header file for windows | |
#include <stdio.h> //C standard library | |
void SetColor(int ForgC); | |
int main() | |
{ | |
SetColor(34); | |
printf("test colour"); | |
return 0; | |
} | |
void SetColor(int ForgC) | |
{ | |
WORD wColor; | |
//We will need this handle to get the current background attribute | |
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); | |
CONSOLE_SCREEN_BUFFER_INFO csbi; | |
//We use csbi for the wAttributes word. | |
if(GetConsoleScreenBufferInfo(hStdOut, &csbi)) | |
{ | |
//Mask out all but the background attribute, and add in the foreground color | |
wColor = (csbi.wAttributes & 0xF0) + (ForgC & 0x0F); | |
SetConsoleTextAttribute(hStdOut, wColor); | |
} | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment