Color in Visual C++ 6.0

Programming, for all ages and all languages.
Post Reply
mekaj

Color in Visual C++ 6.0

Post by mekaj »

I've seen some posts about using color in C++ and have read a bit about it but I'm still lost. Just to be clear, I am working on creating DOS programs. I have seen a DOS program created solely by C++ generate color so I know it can be done.

I read somewhere that you need to include the graphics.h file. Unfortunately, if you look in the library of header files included with Visual C++, the graphics.h file is not there. I also have an old Borland C++ compiler () and it actually does have the graphics.h file.

The command you're supposed to use to change the color, according to what I've read, is setcolor(<colorvalue>). Well I made a simple little program in Borland where I included graphics.h and a command to change the color. When I tried to run it, I got an error relating to the header file. It was saying something about how it wouldn't work w/ windows. I make DOS programs but they run through a command prompt window in windows. Do I have to find a compiler that works in DOS to do this??? Also, can somebody please give me a sample code to change the text color and background color in a DOS program (and address my header file issues)?
Kristian_

Re:Color in Visual C++ 6.0

Post by Kristian_ »

Hi mekaj!
Well, as far as I know in Visual C++ you can't change color for console app's. There is a C++ compiler called Turbo C++, with that you can change text and background color, but you will need to include conio.h header! http://www.google.com/search?hl=com&ie= ... 0ana&meta=
Download the first file of the list! I think it will give you the answer to your question! Hope that help!
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re:Color in Visual C++ 6.0

Post by df »

pdcurses for win32 lets you do it.
-- Stu --
smiddy

Re:Color in Visual C++ 6.0

Post by smiddy »

mekaj wrote: I've seen some posts about using color in C++ and have read a bit about it but I'm still lost. Just to be clear, I am working on creating DOS programs. I have seen a DOS program created solely by C++ generate color so I know it can be done.

I read somewhere that you need to include the graphics.h file. Unfortunately, if you look in the library of header files included with Visual C++, the graphics.h file is not there. I also have an old Borland C++ compiler () and it actually does have the graphics.h file.

The command you're supposed to use to change the color, according to what I've read, is setcolor(<colorvalue>). Well I made a simple little program in Borland where I included graphics.h and a command to change the color. When I tried to run it, I got an error relating to the header file. It was saying something about how it wouldn't work w/ windows. I make DOS programs but they run through a command prompt window in windows. Do I have to find a compiler that works in DOS to do this??? Also, can somebody please give me a sample code to change the text color and background color in a DOS program (and address my header file issues)?
Wow, how does one start here. First it isn't a good idea to mix headers from different compilers without a lot of re-programming in order to make all the function work with the new compiler. Second, I haven't found a way to get Visual C++ 6.0 to compile DOS programs...that doesn't mean that it isn't possible, however I don't know anyone doing it. You can use Watcom's C compiler however to work from within Windows XP and compile for DOS (or OS/2, Windows, etc.). Watcom's conventions on graphics modes might be slightly different (I haven't done any graphics programming from Watcom) but should be somewhat similar. Otherwise you may have to write your own graphics functions using the BIOS routines (INT 0x10) or perhaps the DOS routines (INT 0x21 and possibly others). This may require learning some assemly language too. Another possibility is that the Borland Turbo C compiler you have has its own graphics header and routines (I can't recall what it is called; I'm at work without my references; I will look them up when I get home. I think Borland has a free compiler too...but it may not have graphics routines either, which puts you back to building your own either through BIOS, DOS, or low level I/O.
Post Reply