Since BGI is obsolete, and a lot of its source code seems to be missing from the original website, I've been meaning to design my own color engine that will affect lines individually. So far, the 16 colors that "SetConsoleTextAttribute ()" from windows.h can accept have been doing fine, but I've been meaning to use more colors (by using RGB instead of 0xbf) to upgrade the look of it and color my own ASCII art.
"SetTextColor ()" seems to be the route I want to go. I've set up a testing function to see if it works. Here's the snippet of code with the setup.
HDC hType; // Handle DC, save some work to reduce repetition
int initColor () // Initializes engine
{
hType = GetDC (GetConsoleWindow ());
printf ("String Hexadecimal\n");
testcolorR (RGB(255, 0, 0)); // Red
testcolorR (RGB(0, 255, 0)); // Green
testcolorR (RGB(0, 0, 255)); // Blue
getch (); // Pause to see results
return 0; // Exit success
}
// Take in RGB
void colortextR (COLORREF rgbcolor)
{
SetTextColor (hType, rgbcolor);
}
// Test RGB colors
int testcolorR (COLORREF color)
{
colortextR (color);
printf ("Hello %#x\n", color);
return 0;
}
However, on the command line, the color did not change and remained as the default light-gray, but this is the result.
- String Hexadecimal
- Hello 0xff
- Hello 0xff00
- Hello 0xff0000
Which means that the RGB color is being passed, but something else is causing this problem. I suspect the culprit is the GetConsoleWindow () function.