SetColor - A Console-Window Color-Changing Tool | CodeGuru

SetColor – A Console-Window Color-Changing Tool

This source and application has been released into the public domain by Simon Cooke (spectecjr@getwired.com) It is provided as is, and no liability is assumed by the author for any problems it may cause. It appears to work fine 🙂 SetColor A Win32 console-mode app that allows the user to set the color of following […]

Written By
CodeGuru Staff
CodeGuru Staff
Aug 5, 2000
2 minute read
CodeGuru content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More

This source and application has been released into the public domain by Simon Cooke
(spectecjr@getwired.com)

It is provided as is, and no liability is assumed by the author for any problems it may cause.
It appears to work fine 🙂

SetColor

A Win32 console-mode app that allows the user to set the color of following output text.
This is somewhat better than the COLOR batch command, which forces the entire console window
to change color.

Handy for colorizing batch scripts, and signalling error conditions.

Files

  • SetColor.cpp – source code for setcolor utility.
  • SetColor.exe – setcolor utility

Usage

The app is called with a two-character parameter.

setcolor <foregroundcolor><backgroundcolor>

The parameter is:

  • 0 Black
  • 1 Blue
  • 2 Red
  • 3 Magenta
  • 4 Green
  • 5 Cyan
  • 6 Yellow
  • 7 Gray
  • 8 Dark Gray
  • 9 Bright Blue
  • a Bright Red
  • b Bright Magenta
  • c Bright Green
  • d Bright Cyan
  • e Bright Yellow
  • f Bright White

If foreground = background, the command does nothing.

Examples

c:/>setcolor fa

– all text output following the command will appear in bright white on a red background.

c:/>setcolor D0

– all text output will be in bright cyan, on a black background.

Advertisement

Compilation notes

Does not use the Microsoft C runtime library for space reasons. Imports kernel32.lib ONLY (ignores default libraries); compiled with
minimize size, function level linking, debug output as map-file only, release mode turned on. Linker was set to use 32 byte alignment
for size reasons [see notes]; compiled executable is 2Kb long.

Note: No usage information is compiled into the app to minimize size; static data entails another segment in the generated executable, which
takes up space. Read The Frickin’ Manual 🙂

Notes

May not work as-is on Windows 98; will work fine on Windows 2000/Windows NT4.0. This is because it was compiled with an alignment
setting of 32 to minimize the size of the final application.

Downloads

Download demo project – 1 Kb

Download source – 2 Kb

CodeGuru Logo

CodeGuru covers topics related to Microsoft-related software development, mobile development, database management, and web application programming. In addition to tutorials and how-tos that teach programmers how to code in Microsoft-related languages and frameworks like C# and .Net, we also publish articles on software development tools, the latest in developer news, and advice for project managers. Cloud services such as Microsoft Azure and database options including SQL Server and MSSQL are also frequently covered.

Property of TechnologyAdvice. © 2026 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.