Windows API将输出颜色输出到Powershell / cmd.exe中的stdout

时间:2022-06-11 00:05:39

Anyone know where to find a reference that describes how to output color on the Windows CLI interfaces using API and/or stdout?

任何人都知道在哪里可以找到描述如何使用API​​和/或stdout在Windows CLI界面上输出颜色的参考?

4 个解决方案

#1


3  

The Win32 console API has a function, SetConsoleTextAttribute, that can be used to set the text foreground and background colours. Sample code is here.

Win32控制台API有一个函数SetConsoleTextAttribute,可用于设置文本前景色和背景色。示例代码在这里。

#2


1  

At least there is the color command:

至少有颜色命令:

color bg fg

where:

0: Black
1: Blue
2: Green
3: Cyan
4: Red
5: Purple
6: Yellow
7: Gray
8: Silver
9: Light blue
A: Lime
B: Light cyan
C: Light red
D: Light purple
E: Light yellow
F: White

Example:

color 80

Gives a silver background with black text.

给出带有黑色文字的银色背景。

#3


1  

Not exactly a reference but it should help you find what you're looking for on MSDN, check out:

不完全是参考,但它应该可以帮助您找到您在MSDN上寻找的内容,请查看:

http://www.gamedev.net/community/forums/topic.asp?topic_id=457528.

You probably want to look up "WriteConsoleOutput".

您可能想要查找“WriteConsoleOutput”。

#4


0  

in powershell write-host takes -backgroundcolor and -foregroundcolor parameters

在powershell中,write-host采用-backgroundcolor和-foregroundcolor参数

#1


3  

The Win32 console API has a function, SetConsoleTextAttribute, that can be used to set the text foreground and background colours. Sample code is here.

Win32控制台API有一个函数SetConsoleTextAttribute,可用于设置文本前景色和背景色。示例代码在这里。

#2


1  

At least there is the color command:

至少有颜色命令:

color bg fg

where:

0: Black
1: Blue
2: Green
3: Cyan
4: Red
5: Purple
6: Yellow
7: Gray
8: Silver
9: Light blue
A: Lime
B: Light cyan
C: Light red
D: Light purple
E: Light yellow
F: White

Example:

color 80

Gives a silver background with black text.

给出带有黑色文字的银色背景。

#3


1  

Not exactly a reference but it should help you find what you're looking for on MSDN, check out:

不完全是参考,但它应该可以帮助您找到您在MSDN上寻找的内容,请查看:

http://www.gamedev.net/community/forums/topic.asp?topic_id=457528.

You probably want to look up "WriteConsoleOutput".

您可能想要查找“WriteConsoleOutput”。

#4


0  

in powershell write-host takes -backgroundcolor and -foregroundcolor parameters

在powershell中,write-host采用-backgroundcolor和-foregroundcolor参数