Anyone know where to find a reference that describes how to output color on the Windows CLI interfaces using API and/or stdout?
+1
A:
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.
Gamecat
2008-10-30 20:43:12
OMFG, Was it *SO* hard from them to follow the ECMA-48 standard, at least when it comes to the color numbers!?! It's set up the way for a reason! 1 is blue, what the fuck is that! Red comes before blue, It's RGB not BGR.
Mark Tomlin
2010-04-22 05:04:33
A:
in powershell write-host takes -backgroundcolor and -foregroundcolor parameters
Jimmy
2008-10-30 20:46:53
Even cooler, it accepts an array as a parameter! So this is valid and produces Pink: `write-host "I'm Pink" -ForegroundColor Red, Blue`
Mark Tomlin
2010-04-22 05:54:31
wow, that makes no sense at all to me. it uses the sum of the color values as the result?
Jimmy
2010-04-22 17:06:56
+3
A:
The Win32 console API has a function, SetConsoleTextAttribute, that can be used to set the text foreground and background colours. Sample code is here.
ChrisN
2008-10-30 20:48:15
+1
A:
Not exactly a reference but it should help you find what you're looking for on MSDN, check out:
http://www.gamedev.net/community/forums/topic.asp?topic_id=457528.
You probably want to look up "WriteConsoleOutput".
Leon Sodhi
2008-10-30 20:48:30