PDA

View Full Version : How do you add colour to the text in DOS?



techie
09-28-2001, 04:44 PM
Doe's anyone know how to add colour to DOS programs? I use C++ and I would like to know how to use colour instead of the boring white text as usual. If you know then please post how to on this board and show some source code!:)

DavidP
09-28-2001, 05:46 PM
Include conio.h. Then use the following function:

textcolor(int color)

That will change the text color, but it does not come into effect unless you clear the screen:

clrscr();

So, here is some example code:

#include <iostream.h>
#include <conio.h>

int main (void)
{
textcolor(RED);
clrscr();
cout << "Hello, World!";
getch();
return 0;
}

Hillbillie
09-28-2001, 09:18 PM
It (textcolor()) does come into effect, but you have to use the right functions. I think all output functions that use direct access will work (putch(), cprintf(), etc...).

no-one
09-30-2001, 11:10 AM
to prevent confuson i'll ask first, are you usin a console?

techie
09-30-2001, 01:38 PM
I am using a console and not a GUI program.

no-one
09-30-2001, 06:11 PM
repost,

the colors can be mixed

FOREGROUND_BLUE Text color contains blue.
FOREGROUND_GREEN Text color contains green.
FOREGROUND_RED Text color contains red.
FOREGROUND_INTENSITY Text color is intensified.
BACKGROUND_BLUE Background color contains blue.
BACKGROUND_GREEN Background color contains green.
BACKGROUND_RED Background color contains red.
BACKGROUND_INTENSITY Background color is intensified.




#include <windows.h>

int main()
{

HANDLE hStdout;
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdout, FOREGROUND_RED);

printf("WWWWOOOOO MY TEXT IS RED WWOOOOO!!");
return 0;
}

st0ic
10-17-2001, 12:52 PM
Ah, I don't do C++, so I was wondering about doing the eqivulent in C? I'm not really aware of any functions that can do that in C. Any comments would be apperciated....

Thanks.

no-one
10-18-2001, 11:08 PM
that is C, it should work fine...

st0ic
10-19-2001, 11:55 AM
Ops.. my bad. Well, thanks for the info anyways...