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.
Printable View
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.
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.
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 :)
how do you actually use them?
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.
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.
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
Hi Goof Program
you are missing " at the end of you last cprintf statment
sall
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");
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.
// 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;
}
#include<iostream.h>
cout << endl;
//remember this?
cprintf() does end a line but it will continue at where it left off.
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)
well... the textcolor(); function works only with borland compilers
U can use coni.h on dev c++ and other compilers check my post on Game programming
That's because Visual C doesn't use textcolor. You have to do this:Quote:
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;
}
You can NOT use conio.h w/ VC++. I've already attempted it numerous times on two different computers.Code:#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;
}
Found a way for making it go the RIGHT way >>
Code:#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;
}