AlgoRythm
AlgoRythm

Reputation: 1389

Windows c change console color values

Currently, I'm doing this to change my console colors:

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), BACKGROUND_GREEN);

But what if I wanted to set the background color to, for example, #64e0fc? I know the console can render different colors (You can set them in the properties), but do I have any control over the colors displayed?

Upvotes: 1

Views: 1527

Answers (1)

iBug
iBug

Reputation: 37227

The Windows console uses a 4-bit color palette, so you can have a maximum of 16 colors for foreground and background. The exact values are defined in the registry and is modifiable.

HKEY_CURRENT_USER\Console\ColorTable##
HKEY_CURRENT_USER\Console\(program)\ColorTable##

Where ## is two digits from 00 to 15.

A program can set the color palette by calling SetConsoleScreenBufferInfoEx(), but will not be able to handle more than 16 colors at a time.

Take note that the format for DWORD COLORREF:

When specifying an explicit RGB color, the COLORREF value has the following hexadecimal form:

0x00BBGGRR

Upvotes: 2

Related Questions