Color Text...

Started by
8 comments, last by Elwren 22 years, 9 months ago
Hey, I was wondering if I am programming in DOS and C++, do I have to enter a certain video mode in order to get colored text. I wouldn''t think you would have to, but I''m probably wrong. If anyone knows where I can learn about colored text in DOS, please share Thanks
Advertisement
I also would like to know this...

~~~~
sjunkim - P0et
Liquid Ice Studios
members.home.net/liquidicestudios/
~~~~sjunkimLiquid Ice Studioswww.liquidicestudios.com
Unless you are using a Win32 console, I believe you do have to switch to another video mode.
As I end up pointing out at least once every week, DOS != Win32 Console.

So, if you''re talking about a Win32 Console app, you''ll use the Console functions such as SetConsoleTextAttribute. Consult MSDN for more info on those.

Otherwise, you''re legitimately talking about DOS, in which case you''ll have to mess with some interrupts to make the BIOS do this for you.
If you are using dos, you can use ANSI colour codes

make sure your config.sys includes ''set device=ansi.sys'' (you may need to include a path -ie, for windows OS it''s usually ''c:\windows\command\ansi.sys'' )

then you can use ansi escape sequences ESC[32c for instance. (where ESC is character 27 i think (from memory - been a while - look for the codes somewhere like oulu))

This will also work in windows console mode btw. And it lets you position text on the screen as well as colouring it.

- Wyzfen
You said you were coding C++ in DOS. Hmmm... I think there was setcolor and setbkcolor-functions which changed the colors. Like setcolor(1); --> sets blue etc... setbkcolor(1); --> sets background to blue.
Hope this helps!
Sadly, those functions are compiler-specific (and obviously non-standard, though that''s not an issue here). To my knowledge, they''re only available with Turbo C++, and you''d include conio.h. And you might have to use the output functions in conio.h to use the color, such as cprintf and cputs--I don''t quite remember.
If you use the ANSI escape sequences you can use any output functions you like... as long as it eventually goes to standard out.

If you are using WindowsME, though, you can no longer load older DOS drivers. As a matter of fact, you can''t even modify the blank autoexec.bat or config.sys that resides in the root directory.
I havent tried this yet, so it might work using the system() command in a console. The system() comman lets you use old DOS commands in the console applications. Example: system("c:\dir")
this prints a directory listing. I thought there was a command in dos that let you set the colors of your text on the fly this might be the way to implement it.

"There is humor in everything depending on which prespective you look from."
"There is humor in everything depending on which prespective you look from."
I havent tried this yet, so it might work using the system() command in a console. The system() comman lets you use old DOS commands in the console applications. Example: system("dir")
this prints a directory listing. I thought there was a command in dos that let you set the colors of your text on the fly this might be the way to implement it.

"There is humor in everything depending on which prespective you look from."

This topic is closed to new replies.

Advertisement