• ### Announcements

#### Archived

This topic is now archived and is closed to further replies.

# Color Text in Console Mode Programs?

## Recommended Posts

Is it possible to change the color of the text in a console mode program. (Under windows) I tried using ANSI escape codes, but no luck. How do you change the color in C under DOS? (It might the same) Can I call int10 (in assembly) under windows console mode?

##### Share on other sites
No, I don't think you can use int 10 (or any intterupt) under console programs. You can do it the "Win32 way" using SetConsoleTextAttribute(). It needs a handle to the consoel screen buffer as an argument so you can either call GetStdHandle() early and save it as a global or just wrap the whole thing in a function, like this:

  int ChangeTextColor(WORD text_attribute){ HANDLE screen_buffer; screen_buffer = GetStdHandle(STD_OUTPUT_HANDLE); SetConsoleTextAttribute(screen_buffer, text_attribute); return(1);}

And to call it you make a call like:

ChangeTextColor(FOREGROUND_BLUE);
ChangeTextColor(FOREGROUND_BLUE / BACKGROUND_RED / FOREGROUND_INTENSITY);
or whatever. The arguments can be any of the combination of the following (taken out of the VC++ help):

FOREGROUND_BLUE, FOREGROUND_GREEN, FOREGROUND_RED, FOREGROUND_INTENSITY, BACKGROUND_BLUE, BACKGROUND_GREEN, BACKGROUND_RED, and BACKGROUND_INTENSITY

Note it is supposed to be a pipe instead of the back slash. I guess HTML formats the pipes to back slashes for some reason. If you don't know a pipe is just shift+back slash. And I know there is probably an alt combination or whatever that gives you pipes but I'm too lazy to look it up.

Edited by - Sheltem on June 20, 2000 2:40:19 AM

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627689
• Total Posts
2978659

• 18
• 14
• 12
• 10
• 12