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

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Closed Thread

Join Date: Dec 2004
Posts: 151
Reputation: Geek-Master is an unknown quantity at this point 
Solved Threads: 6
Geek-Master's Avatar
Geek-Master Geek-Master is offline Offline
Junior Poster

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

 
0
  #11
Dec 28th, 2004
Just somthing I made with the bit of info I learned from this thread. It also can be a simulation of those "test" the video broadcasters do for some reason. Let me know what you guys-n-gals think LOL :cheesy:

  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <windows.h>
  4.  
  5. int color();
  6.  
  7. int main()
  8. {
  9. int c;
  10. for (c = 0; c < 24; c++)
  11. {
  12. color();
  13. }
  14. system("pause");
  15. return 0;
  16. }
  17.  
  18. int color()
  19. {
  20. HANDLE hConsole;
  21. int k = 0, r;
  22. for (r = 0; r < 16; r++)
  23. {
  24. hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  25. k;
  26. SetConsoleTextAttribute(hConsole, k);
  27. cout << "ÛÛÛÛÛ"; // Alt 219 (a square) extended ASCII character
  28. k++;
  29. }
  30. return 0;
  31. }
Quick reply to this message  
Join Date: Sep 2004
Posts: 7,829
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: 750
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

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

 
0
  #12
Dec 28th, 2004
>I think you should leave C++ alone. Go play with QBasic, as it's more your style.
I think you should be silent unless you have something useful to add. Flames are fine as long as they're deserved, but in this case your comments are completely uncalled for.

>Oh, and Dexter's Laboratory sucks.
Personal opinions have no place here unless they're related to C or C++ and carefully worded to make it clear that they're opinions.

If you want to be an ass, at least do it tastefully.

>Let me know what you guys-n-gals think LOL
Well, I think that LOL should only be used in response to something incredibly funny, if at all. Using LOL in response to a statement you make gives the impression that you're a lamer.

Aside from that, the code could be formatted better, it could be reorganized, and you make an assumption about the size of the console window. Here's another way to go about it:
  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <windows.h>
  4.  
  5. void color();
  6.  
  7. int main()
  8. {
  9. HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  10. COORD windowSize = GetLargestConsoleWindowSize(hConsole);
  11.  
  12. for (SHORT c = 0; c < windowSize.Y; c++)
  13. {
  14. color();
  15. }
  16. std::system("pause");
  17.  
  18. return 0;
  19. }
  20.  
  21. void color()
  22. {
  23. HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  24. WORD k = 0;
  25. const int colors = 16;
  26.  
  27. for (int r = 0; r < colors; r++)
  28. {
  29. SetConsoleTextAttribute(hConsole, k++);
  30. std::cout << "ÛÛÛÛÛ"; // Alt 219 (a square) extended ASCII character
  31. }
  32. }
All in all, a nice program. Well done.
New members chased away this month: 3
Quick reply to this message  
Join Date: Oct 2004
Posts: 4,113
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: 944
Moderator
vegaseat's Avatar
vegaseat vegaseat is offline Offline
DaniWeb's Hypocrite

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

 
0
  #13
Dec 28th, 2004
Originally Posted by Geek-Master
Just somthing I made with the bit of info I learned from this thread. It also can be a simulation of those "test" the video broadcasters do for some reason. Let me know what you guys-n-gals think LOL :cheesy:

  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <windows.h>
  4.  
  5. int color();
  6.  
  7. int main()
  8. {
  9. int c;
  10. for (c = 0; c < 24; c++)
  11. {
  12. color();
  13. }
  14. system("pause");
  15. return 0;
  16. }
  17.  
  18. int color()
  19. {
  20. HANDLE hConsole;
  21. int k = 0, r;
  22. for (r = 0; r < 16; r++)
  23. {
  24. hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  25. k;
  26. SetConsoleTextAttribute(hConsole, k);
  27. cout << "ÛÛÛÛÛ"; // Alt 219 (a square) extended ASCII character
  28. k++;
  29. }
  30. return 0;
  31. }
I hope my somewhat imperfect code got you started! Nice to see that you are thinking in a creative way!
May 'the Google' be with you!
Quick reply to this message  
Join Date: Mar 2004
Posts: 1,620
Reputation: kc0arf is a jewel in the rough kc0arf is a jewel in the rough kc0arf is a jewel in the rough 
Solved Threads: 51
Team Colleague
kc0arf kc0arf is offline Offline
Posting Virtuoso

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

 
0
  #14
Dec 28th, 2004
Play nice people. Attitude, name calling, grumpy behavior, or posting without having your Wheaties in the morning will not help us become better coders. And we all should admit that sometimes the documentation / examples that are in the book, or online resource, do not jump out and click.

Locking thread to encourage better use of our time.

Christian
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



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC