How to code a program that can show color text output???

Closed Thread

Join Date: Oct 2004
Posts: 22
Reputation: kakilang is an unknown quantity at this point 
Solved Threads: 0
kakilang's Avatar
kakilang kakilang is offline Offline
Newbie Poster

How to code a program that can show color text output???

 
0
  #1
Oct 26th, 2004
can someone teach me or show me how to code a program that can output color text?? thx :p
Quick reply to this message  
Join Date: Sep 2004
Posts: 7,567
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 707
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: How to code a program that can show color text output???

 
0
  #2
Oct 26th, 2004
This is an implementation-dependent operation. Without knowing your platform and compiler, we can't help you at all.
I'm here to prove you wrong.
Quick reply to this message  
Join Date: Oct 2004
Posts: 22
Reputation: kakilang is an unknown quantity at this point 
Solved Threads: 0
kakilang's Avatar
kakilang kakilang is offline Offline
Newbie Poster

Re: How to code a program that can show color text output???

 
0
  #3
Oct 27th, 2004
i am using dev c++ 4.9.9 compiler and windows xp

below is a simple source code

#include<iostream>
using namespace std;

int main()
{
cout<<"Hello"<<endl;
system("pause");
return 0;
}

how to let the program print the "hello" string with color and also how to set the background color??
Quick reply to this message  
Join Date: Sep 2004
Posts: 7,567
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 707
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: How to code a program that can show color text output???

 
0
  #4
Oct 27th, 2004
Search MSDN for SetConsoleTextAttribute.
I'm here to prove you wrong.
Quick reply to this message  
Join Date: Oct 2004
Posts: 22
Reputation: kakilang is an unknown quantity at this point 
Solved Threads: 0
kakilang's Avatar
kakilang kakilang is offline Offline
Newbie Poster

Re: How to code a program that can show color text output???

 
0
  #5
Oct 27th, 2004
still can't understand can u show me some example source code
Quick reply to this message  
Join Date: Sep 2004
Posts: 7,567
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 707
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: How to code a program that can show color text output???

 
0
  #6
Oct 27th, 2004
>still can't understand can u show me some example source code
No, why don't you try experimenting instead of mooching off everyone else. This isn't a terribly difficult task, and by working it out on your own you'll learn much more than if I just gave you code to copy.
I'm here to prove you wrong.
Quick reply to this message  
Join Date: Oct 2004
Posts: 22
Reputation: kakilang is an unknown quantity at this point 
Solved Threads: 0
kakilang's Avatar
kakilang kakilang is offline Offline
Newbie Poster

Re: How to code a program that can show color text output???

 
0
  #7
Oct 27th, 2004
i really dun understand all the things in MSDN
Quick reply to this message  
Join Date: Oct 2004
Posts: 3,947
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 914
Moderator
vegaseat's Avatar
vegaseat vegaseat is online now Online
DaniWeb's Hypocrite

Re: How to code a program that can show color text output???

 
0
  #8
Oct 27th, 2004
Looks like Narue is in the usual good mood this morning.
You have to forgive! Good person though!

I took BCX, the basic to C translator, and figured it out in 5 minutes flat. Here is the C code. You may throw in a little C++ lingo. The name of the WinApi header may be different with your compiler. Play with k a little to get the feel!
  1. // change text color in Windoze console mode
  2. // colors are 0=black 1=blue 2=green and so on to 15=white
  3. // colorattribute = foreground + background * 16
  4. // to get red text on yellow use 4+14*16
  5. // tested with Pelles C (vegaseat)
  6.  
  7. #include <stdio.h>
  8. #include <windows.h> // or other WinApi header
  9.  
  10.  
  11. int main()
  12. {
  13. HANDLE hConsole;
  14. int k;
  15.  
  16. hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  17.  
  18. for(k = 1; k < 25; k++)
  19. {
  20. SetConsoleTextAttribute(hConsole, k);
  21. printf("%2d %s\n", k, "I want to be nice today!");
  22. }
  23.  
  24. getchar(); // cheap wait
  25. return 0;
  26. }
Actually, programming can be fun ...
a man, sorry, person over machine thing!
May 'the Google' be with you!
Quick reply to this message  
Join Date: Oct 2004
Posts: 22
Reputation: kakilang is an unknown quantity at this point 
Solved Threads: 0
kakilang's Avatar
kakilang kakilang is offline Offline
Newbie Poster

Re: How to code a program that can show color text output???

 
0
  #9
Oct 28th, 2004
thx for ur help vegaseat.

Do u know how to let the text in the program blink???
Quick reply to this message  
Join Date: Sep 2004
Posts: 7,567
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 707
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: How to code a program that can show color text output???

 
0
  #10
Oct 28th, 2004
Do you now see what happens vegaseat? If you give them the answer then they'll stop thinking for themselves--assuming they thought for themselves in the first place--and expect you to continue giving them the answer. The goal here is not to solve the problems of others, but to teach others how to solve their own problems.

>Do u know how to let the text in the program blink???
I know how to make text blink, but I'm not going to tell you because one method is easy to figure out using what you just learned.
I'm here to prove you wrong.
Quick reply to this message  
Closed Thread

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



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