有没有办法在 Windows 控制台中获得更多颜色(c++)?
有没有办法在 Windows 控制台(C++)中获得更多颜色?
我所说的“更多”是指 RGB 颜色。我尝试过:
CONSOLE_SCREEN_BUFFER_INFOEX info;
info.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX);
HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfoEx(hcon, &info);
info.ColorTable[0] = 0x505050;
info.ColorTable[1] = 0xcccccc;
SetConsoleScreenBufferInfoEx(hcon, &info);
SetConsoleTextAttribute(hcon, 01);
但我一次只能使用16种颜色。
Is there a way to get more colors in Windows console (c++)?
By "more", I mean RGB colors. I have tried:
CONSOLE_SCREEN_BUFFER_INFOEX info;
info.cbSize = sizeof(CONSOLE_SCREEN_BUFFER_INFOEX);
HANDLE hcon = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfoEx(hcon, &info);
info.ColorTable[0] = 0x505050;
info.ColorTable[1] = 0xcccccc;
SetConsoleScreenBufferInfoEx(hcon, &info);
SetConsoleTextAttribute(hcon, 01);
but I can use only 16 colors at one time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自控制台 API 的一些文档,特别是与 扩展颜色的虚拟终端序列:
基于此,我假设 Windows 控制台不支持超过 16 种颜色。如果我不得不猜测的话,这是与假设只有 16 种颜色的程序交互的向后兼容性限制。
如果您想要更多,最好不要使用 Windows 控制台。如果这不可能,那么您就只能得到总共 16 个。
From some of the documentation on the console API, specifically relating to Virtual Terminal Sequences for Extended Color:
Based on this, I'd make the assumption that the Windows Console doesn't support anything more than 16 colors. If I had to guess, this is a backwards-compatibility restriction to interact with programs that assumed there were only ever 16 colors.
If you want more, you'd be best served by not using the Windows Console. If that's not possible, then you're stuck with 16 total.
您必须使用 VT 颜色序列。
像这样启用:
此示例显示了它可以执行的操作:
You have to the use VT color sequences.
Enable like so:
This example, shows what it can do: