how to make colors

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2004
Posts: 19
Reputation: matika is an unknown quantity at this point 
Solved Threads: 0
matika matika is offline Offline
Newbie Poster

how to make colors

 
0
  #1
May 25th, 2004
i'm working on a project and i really want to know if c++ provides to print out colored text or not.
thx
Reply With Quote Quick reply to this message  
Join Date: Feb 2002
Posts: 12,035
Reputation: cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light cscgal is a glorious beacon of light 
Solved Threads: 128
Administrator
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: how to make colors

 
0
  #2
May 25th, 2004
As far as I know, this can be accomplished. Printing to a hardware printer is simply a level of abstraction that can be accomplished via printer drivers, etc. I did a quick Google search and came up with this ... I don't know if it will be of much help to you: http://www.programmersheaven.com/zone3/cat973/21965.htm
Dani the Computer Science Gal
Follow my Twitter feed! twitter.com/daniweb
Reply With Quote Quick reply to this message  
Join Date: Mar 2004
Posts: 219
Reputation: BountyX is an unknown quantity at this point 
Solved Threads: 8
BountyX's Avatar
BountyX BountyX is offline Offline
Code Guru

Re: how to make colors

 
0
  #3
May 27th, 2004
msdn.com "C++, Printers"

if you mean print as in output to the screen, check out the other thread above.
A Hacker's Mind:
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes..." - J.D.Salinger
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 256
Reputation: FireNet will become famous soon enough FireNet will become famous soon enough 
Solved Threads: 6
FireNet's Avatar
FireNet FireNet is offline Offline
Posting Whiz in Training

Re: how to make colors

 
0
  #4
May 27th, 2004
You mean to the paper or the screen.

if you want on the screen use conio.h

Colors
------
  1.  
  2. 0 BLACK /* dark colors */
  3. 1 BLUE
  4. 2 GREEN
  5. 3 CYAN
  6. 4 RED
  7. 5 MAGENTA
  8. 6 BROWN
  9. 7 LIGHTGRAY
  10.  
  11. 8 DARKGRAY /* light colors */
  12. 9 LIGHTBLUE
  13. 10 LIGHTGREEN
  14. 11 LIGHTCYAN
  15. 12 LIGHTRED
  16. 13 LIGHTMAGENTA
  17. 14 YELLOW
  18. 15 WHITE

1.textbackground(int) to change the background color
2.textcolor(int) to change text color

Now you can call any to the above funtions as below:
textcolor(2); //green color
textcolor(BLUE); //blue text color( see the above list for more colors)

in C++ sometimes you will have to call clrscr() to clear the screen before the changes will become visible.

if you call clreol() [clear till end of line] only that line will be affected.Then when new text is typed on the next line sometimes the changes will remain other wise the old settings.

This varies from complier to compiler.I have no idea why.

gotoxy(int x,int y); //shift text cursor location, starts at 1,1

Helps ? :!:
See what you can, remember what you need

Fourzon | Earn via Coding
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 34
Reputation: Fili is an unknown quantity at this point 
Solved Threads: 0
Fili's Avatar
Fili Fili is offline Offline
Light Poster

Re: how to make colors

 
0
  #5
Jun 18th, 2004
You're right Fire Net.

The colour list is ok. you know that's why i use printf/scanf

In <conio.h> you may find: cprintf(...);cscanf(...) with the same paramters as ...scanf() and ...printf() functions. The difference is that it reads and writes in colours! The textcolor is changed through textcolor() function described by Fire Net. Also, keep in mind that you can make the text blink!: textcolor(BLUE+BLINK). clrscr(void) clears the screan and clreol erases the current line. gotoxy(int x,int y) sets the screen coordinates(where to write) wherex(void);wherey(void) return screen coordinates x=wherex(); I nearly forgot: cputs(char *s) writes a coloured string and cgets(char *s) reads a colour string. In <conio.h> there are even more functions:
-getch(void) gets a character - can be used to stop program execution until a key is pressed----!!!!does not echo on screen
-getche(void) is exactly the same but echos on screen.
-ungetch(void) sends the las read characte back to stdin making it the next character to be read
-kbhit(void) tests if a key was pressed--useful in loops:
while (!kbhit()) putch("a");
-putch(char c) writes the character on screen

I can't remember anything else!!!!!
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 173
Reputation: BinaryMayhem is an unknown quantity at this point 
Solved Threads: 9
BinaryMayhem BinaryMayhem is offline Offline
Unverified User

Re: how to make colors

 
1
  #6
Jun 19th, 2004
mmhmmm, those are all nice and good until you use vc6++ where you can only create console applications.

here are some api calls you can use instead.

hwnd_type { STD_INPUT_HANDLE, STD_OUTPUT_HANDLE, STD_ERROR_HANDLE}
GetStdHandle(hwnd_type)
SetConsoleCursorPosition (handle, cordinates)
SetConsoleTextAttribute(handle, color)

** there a too many to list... so im not going too. However, a complete list can be found in the MSDN.

you need to include windows.h for this.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 34
Reputation: Fili is an unknown quantity at this point 
Solved Threads: 0
Fili's Avatar
Fili Fili is offline Offline
Light Poster

Re: how to make colors

 
0
  #7
Jun 20th, 2004
Originally Posted by BinaryMayhem
mmhmmm, those are all nice and good until you use vc6++ where you can only create console applications.
I know they won't work in Visual C but I'm a Borland C++ (for DOS) user. :!:
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC