PDA

View Full Version : different colors



Paveltc
12-16-2001, 09:41 PM
I was wondering if anybody knew what other colors you could use in DOS.

So far I know of the colors blue, green, and red, but when I enter some other colors I get an error.

DavidP
12-16-2001, 10:44 PM
It depends what mode you are using.

if you are in a normal text mode, you have 16 color choices. you can find them in either dos.h, conio.h, or graphics.h. (cant remember which). if you are in a graphics mode, it depends what mode you are in. 13h has 256 24-bit colors, 112h is 16 million, etc.

Yoshi
12-16-2001, 10:58 PM
if you are in a normal text mode, you have 16 color choices. you can find them in either dos.h, conio.h, or graphics.h. (cant remember which).

conio.h it is :)

pully
12-23-2001, 02:15 AM
how do you actually use them?

VirtualAce
12-23-2001, 03:30 AM
You use them by calling settextcolor(). There are other functions in C that allow you to change colors as well. Look in the conio.h header file for more info or your help file.

Yoshi
12-24-2001, 12:01 AM
textcolor(COLOR or corresponding number) = set text color
textbackground(COLOR or corresponding number) = ground of input.

you have to use cprintf() to use it, though. But, no big deal.

Goof Program
12-24-2001, 10:35 AM
When I use the textcolor(); cprintf(); fuctions it messes my program all up because the text does not stay to the left. any way i can fix it?

/*********************************************/
#include <stdio.h>
#include <conio.h>

main()
{
textcolor(RED);
cprintf("this is left\n\n");
textcolor(LIGHTGRAY);
cprintf("back to same color);
return 0;
}
/********************************************/

its does this.
--------------------------------------------------------------------------
this is left <----RED

.......................back to same color <-----not left where i want it

Unregistered
12-25-2001, 12:56 PM
Hi Goof Program
you are missing " at the end of you last cprintf statment

sall

lambs4
12-25-2001, 01:33 PM
try replacing this
cprintf("back to same color);
with this:
cprintf("back to same color\n\r");

correction. it should look like this cprintf("this is left\n\n\r");

sean
12-26-2001, 06:14 PM
Generally there are 16. Look up conio.h and there are #define s for each color, numbered 0-15. This is the only C Runtime library I know of that comes with Borland compilers that has colored-text methods, but I could be wrong.

real_cozzy
01-07-2002, 07:05 PM
// This doesn't compile for me in Visual C.

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <conio.h>


int main()
{
textcolor(RED);
cprintf("this is left\n\n");
textcolor(LIGHTGRAY);
cprintf("back to same color");
return 0;
}

Yoshi
01-07-2002, 11:45 PM
#include<iostream.h>

cout << endl;

//remember this?

cprintf() does end a line but it will continue at where it left off.

real_cozzy
01-08-2002, 01:46 PM
Still get three errors, even with the #include <iostream.h> statement in the file. It doesn't like the textcolor() statement, along with the Color references. What gives?


c:\development\cpp\graphics\graphtest.cpp(10) : error C2065: 'textcolor' : undeclared identifier
c:\development\cpp\graphics\graphtest.cpp(10) : error C2065: 'RED' : undeclared identifier
c:\development\cpp\graphics\graphtest.cpp(12) : error C2065: 'LIGHTGRAY' : undeclared identifier
Error executing cl.exe.

graphtest.exe - 3 error(s), 0 warning(s)

dune911
07-16-2002, 10:38 AM
well... the textcolor(); function works only with borland compilers

datainjector
07-17-2002, 03:17 PM
U can use coni.h on dev c++ and other compilers check my post on Game programming

Quantrizi
07-17-2002, 04:47 PM
Originally posted by real_cozzy
// This doesn't compile for me in Visual C.

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <conio.h>


int main()
{
textcolor(RED);
cprintf("this is left\n\n");
textcolor(LIGHTGRAY);
cprintf("back to same color");
return 0;
}
That's because Visual C doesn't use textcolor. You have to do this:


#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <windows.h>


int main()
{
HANDLE hStdout;
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdout, FOREGROUND_RED);
cprintf("this is left\n\n");
HANDLE hStdout;
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hStdout, FOREGROUND_INTENSITY);
cprintf("back to same color");
return 0;
}

You can NOT use conio.h w/ VC++. I've already attempted it numerous times on two different computers.

Metael
07-19-2002, 10:21 AM
Found a way for making it go the RIGHT way >>



#include <stdio.h>
#include <conio.h>

main()
{
textcolor(RED);
cprintf("this is left");
printf("\n\n");
textcolor(LIGHTGRAY);
cprintf("back to same color");
return 0;
}