DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C (http://www.daniweb.com/forums/forum118.html)
-   -   How to code a program that can show color text output??? (http://www.daniweb.com/forums/thread12945.html)

kakilang Oct 26th, 2004 6:20 am
How to code a program that can show color text output???
 
can someone teach me or show me how to code a program that can output color text?? thx :p

Narue Oct 26th, 2004 9:26 am
Re: How to code a program that can show color text output???
 
This is an implementation-dependent operation. Without knowing your platform and compiler, we can't help you at all.

kakilang Oct 27th, 2004 2:50 am
Re: How to code a program that can show color text output???
 
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??

Narue Oct 27th, 2004 9:34 am
Re: How to code a program that can show color text output???
 
Search MSDN for SetConsoleTextAttribute.

kakilang Oct 27th, 2004 11:13 am
Re: How to code a program that can show color text output???
 
still can't understand can u show me some example source code

Narue Oct 27th, 2004 11:23 am
Re: How to code a program that can show color text output???
 
>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.

kakilang Oct 27th, 2004 11:38 am
Re: How to code a program that can show color text output???
 
i really dun understand all the things in MSDN

vegaseat Oct 27th, 2004 1:06 pm
Re: How to code a program that can show color text output???
 
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!
// change text color in Windoze console mode
// colors are 0=black 1=blue 2=green and so on to 15=white 
// colorattribute = foreground + background * 16
// to get red text on yellow use 4+14*16
// tested with Pelles C  (vegaseat) 

#include <stdio.h>
#include <windows.h>  // or other WinApi header


int main()
{
  HANDLE  hConsole;
        int k;
       
  hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

  for(k = 1; k < 25; k++)
  {
    SetConsoleTextAttribute(hConsole, k);
    printf("%2d  %s\n", k, "I want to be nice today!");
  }

  getchar();  // cheap wait
  return 0;
}
Actually, programming can be fun ...
a man, sorry, person over machine thing!

kakilang Oct 28th, 2004 3:54 am
Re: How to code a program that can show color text output???
 
thx for ur help vegaseat.

Do u know how to let the text in the program blink???

Narue Oct 28th, 2004 9:30 am
Re: How to code a program that can show color text output???
 
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.


All times are GMT -4. The time now is 7:05 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC