Skip to content

Instantly share code, notes, and snippets.

@boodahDEV
Created February 19, 2019 13:23
Show Gist options
  • Save boodahDEV/8461dd17b6f4338ff01feef95f2287ac to your computer and use it in GitHub Desktop.
Save boodahDEV/8461dd17b6f4338ff01feef95f2287ac to your computer and use it in GitHub Desktop.
Fuente para setear colores por línea en C, desventaja que se necesita importar la libreria "windows.h" lo cual limita en sistemas Linux.
void SetColor(int ForgC){
WORD wColor;
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbi;
if(GetConsoleScreenBufferInfo(hStdOut, &csbi))
{
wColor = (csbi.wAttributes & 0xF0) + (ForgC & 0x0F);
SetConsoleTextAttribute(hStdOut, wColor);
}
return;
}
@boodahDEV
Copy link
Author

Name == Value

Black == 0
Blue == 1
Green == 2
Cyan == 3
Red == 4
Magenta == 5
Brown == 6
Light Gray == 7
Dark Gray == 8
Light Blue == 9
Light Green == 10
Light Cyan == 11
Light Red == 12
Light Magenta == 13
Yellow == 14
White == 15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment