简体   繁体   中英

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?

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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM