简体   繁体   English

Windows C更改控制台颜色值

[英]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 ? 但是,如果我想将背景颜色设置为例如#64e0fc怎么#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. Windows控制台使用4位调色板,因此前景和背景最多可以有16种颜色。 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. 其中##是从00到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. 程序可以通过调用SetConsoleScreenBufferInfoEx()设置调色板,但是一次不能处理16种以上的颜色。

Take note that the format for DWORD COLORREF : 请注意DWORD COLORREF的格式:

When specifying an explicit RGB color, the COLORREF value has the following hexadecimal form: 指定显式RGB颜色时,COLORREF值具有以下十六进制形式:

 0x00BBGGRR 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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