• Advertisement

Archived

This topic is now archived and is closed to further replies.

ASCII iColored n C/C++ URGENT!

This topic is 5527 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

ASCII iColored n C/C++ URGENT! How do you do that? I mean, how do you write ascii characters with color? cout, printf? Is there any function such as LocateText(x,y) or something? Is there any way to access a linear buffer of characters in the screen? (i mean in a polite way, non assembly, i mean standard ansi c, etc) Please help!!! ElPeque __________________ Alejandro Martínez

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by ElPeque
i mean standard ansi c

can't be done.

fast enough?

edit: and PLEASE remove all your other crossposts. few things are more annoying than people crossposting all over the place.

[edited by - niyaw on December 1, 2002 12:23:45 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It''s not part of the ansi standard. What you want to do is inherently platform dependent. I think there is a library called "curses" that does what you want.

Share this post


Link to post
Share on other sites
you are right...

im sorry about that...
___________

Is that true?
i can''t believe it.

WTF!

Even pascal can do that!

and QBASIC!

;O/

__________________
Alejandro Martínez

Share this post


Link to post
Share on other sites
if it''s a windows app.. you can use SetBkColor... etc
There IS a way to generate colored text in a console, but I don''t know how to do that.

Share this post


Link to post
Share on other sites
Im compiling a console program with the compiler "Cygwin". I think it is a port of the UNIX c compiler. So i think ill have to stick to standard (?) c only.

Thanks a lot for the help!! =O)

__________________
Alejandro Martínez

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Well pascal and basic can do it because they call a library written specifically for the platform they are running on. C has libraries that do these things too, it is just not part of the core language.

Share this post


Link to post
Share on other sites
windows.h has the functions you''ll want to use. It''s pretty easy. All you need to do is allocate an array of CHAR_INFO ''s, with the size of the console width * console height, then set any CHAR_INFO in the array using: buffer[(x + (y * width))]
then write your buffer to the screen using some method I can''t remember the name of. Look it up.

Share this post


Link to post
Share on other sites
If you are using Cygwin why don''t you use the conio.h?
There''s a special edition for Cygwin... try find it.

Has very great commands to manipulate the ANSI characters and the screen, like
------------------------
gotoxy( int x, int y );
whereis( int x, int y );

text background and foreground color change

dos cursor hide or show
-------------------------

But, if you are simple using Cygwin and all your console programs will MUST run in a Windows system, why don''t you simple use the Windows Console Headers?

Take a look at the lasts tutorials of this page
http://www.gametutorials.com/Tutorials/c++/Cpp_Pg3.htm

and the firsts of this
http://www.gametutorials.com/Tutorials/c++/Cpp_Pg4.htm

Download the tuts for BloodShed DevC++, because this uses the same system of Cygwin( the Mingwin32 )

I hope it helped!!!
Good Lucky!

Rafael G. Donato

Share this post


Link to post
Share on other sites
quote:
Original post by gip
Download the tuts for BloodShed DevC++, because this uses the same system of Cygwin( the Mingwin32 )



mingw32 uses the Windows API
cygwin uses the POSIX API.

In cygwin gcc -mno-cygwin will use the mingw32 library and the resulting code will not be GPLed; unlike programs otherwise compiled under cygwin.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]

Share this post


Link to post
Share on other sites
Alright, I dunno about printf, but I know this works for cout (in console apps).

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), flags)

Where flags is any mixture of:
BACKGROUND_RED
BACKGROUND_GREEN
BACKGROUND_BLUE
FOREGROUND_RED
FOREGROUND_GREEN
FOREGROUND_BLUE
FOREGROUND_INTENSITY (makes the color brighter)

You can mix colors like this:
FOREGROUND_RED | FOREGROUND_BLUE | BACKGROUND_GREEN
which will produce purple text on a green background

Also, to get back to normal, put all the colors in together (red + blue + green = white!!).

I do not know how to change either of the colors back to black, but I beleive that REVERSE_VIDEO is also a flag that could work in there.

Also, once you make a color change, it will stay until you change it.


  
// Code Example..

// already in program...

// Notice these #define''s -----

#define STDOUT GetStdHandle(STD_OUTPUT_HANDLE)
#define FG_RED FOREGROUND_RED
#define FG_BLUE FOREGROUND_BLUE
#define FG_GREEN FOREGROUND_GREEN
#define BG_GREEN BACKGROUND_GREEN


SetConsoleTextAttribute(STDOUT, FG_RED);
cout << "THIS IS RED!!!" << endl;
SetConsoleTextAttrubute(STDOUT, FG_RED | FG_BLUE);
cout << "THIS IS PURPLE!!! IT LOOKS LIKE BARNEY!!!" << endl;
SetConsoleTextAttribute(STDOUT, BG_GREEN);
cout << "PURPLE ON GREEN!" << endl;
SetConsoleTextAttribute(STDOUT, FG_RED | FD_BLUE | FD_GREEN);
cout << "WHITE ON GREEN!" << endl;

// I''m not sure what this next line will do, but I think

// It will change everything back to normal....

SetConsoleTextAttribute(STDOUT, REVERSE_VIDEO)
cout << "hmmm...." << endl;

Share this post


Link to post
Share on other sites
Alright, I dunno about printf, but I know this works for cout (in console apps).

SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), flags)

Where flags is any mixture of:
BACKGROUND_RED
BACKGROUND_GREEN
BACKGROUND_BLUE
FOREGROUND_RED
FOREGROUND_GREEN
FOREGROUND_BLUE
FOREGROUND_INTENSITY (makes the color brighter)

You can mix colors like this:
FOREGROUND_RED | FOREGROUND_BLUE | BACKGROUND_GREEN
which will produce purple text on a green background

Also, to get back to normal, put all the colors in together (red + blue + green = white!!).

I do not know how to change either of the colors back to black, but I beleive that REVERSE_VIDEO is also a flag that could work in there.

Also, once you make a color change, it will stay until you change it.


  
// Code Example..

// already in program...

// Notice these #define''s -----

#define STDOUT GetStdHandle(STD_OUTPUT_HANDLE)
#define FG_RED FOREGROUND_RED
#define FG_BLUE FOREGROUND_BLUE
#define FG_GREEN FOREGROUND_GREEN
#define BG_GREEN BACKGROUND_GREEN


SetConsoleTextAttribute(STDOUT, FG_RED);
cout << "THIS IS RED!!!" << endl;
SetConsoleTextAttrubute(STDOUT, FG_RED | FG_BLUE);
cout << "THIS IS PURPLE!!! IT LOOKS LIKE BARNEY!!!" << endl;
SetConsoleTextAttribute(STDOUT, BG_GREEN);
cout << "PURPLE ON GREEN!" << endl;
SetConsoleTextAttribute(STDOUT, FG_RED | FD_BLUE | FD_GREEN);
cout << "WHITE ON GREEN!" << endl;

// I''m not sure what this next line will do, but I think

// It will change everything back to normal....

SetConsoleTextAttribute(STDOUT, REVERSE_VIDEO)
cout << "hmmm...." << endl;

Share this post


Link to post
Share on other sites
quote:
Original post by Fruny
[quote]Original post by gip
Download the tuts for BloodShed DevC++, because this uses the same system of Cygwin( the Mingwin32 )



mingw32 uses the Windows API
cygwin uses the POSIX API.

In cygwin gcc -mno-cygwin will use the mingw32 library and the resulting code will not be GPLed; unlike programs otherwise compiled under cygwin.

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]


Well, when I said "same system" I needed put it on quotes, don''t you think?
But I said that because the both uses the gcc/g++ like compiler, so some of header files works in both...
Ok? Thanks for the "correction"


"Be forgotten is worse than death..."



Rafael G. Donato

Share this post


Link to post
Share on other sites
HI!
I defined some color attributes for a textcolor function I coded some time ago.

// background attributes
#define BG_BlACK 0
#define BG_DARKGREY BACKGROUND_INTENSITY
#define BG_RED BACKGROUND_RED
#define BG_ORANGE BACKGROUND_RED | BACKGROUND_INTENSITY
#define BG_GREEN BACKGROUND_GREEN
#define BG_LIGHTGREEN BACKGROUND_GREEN | BACKGROUND_INTENSITY
#define BG_BLUE BACKGROUND_BLUE
#define BG_MEDIUMBLUE BACKGROUND_BLUE | BACKGROUND_INTENSITY
#define BG_GREY BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE
#define BG_WHITE BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY
#define BG_DARKORANGE BACKGROUND_RED | BACKGROUND_GREEN
#define BG_YELLOW BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_INTENSITY
#define BG_TEAL BACKGROUND_GREEN | BACKGROUND_BLUE
#define BG_LIGHTBLUE BACKGROUND_GREEN | BACKGROUND_BLUE | BACKGROUND_INTENSITY
#define BG_VIOLET BACKGROUND_BLUE | BACKGROUND_RED
#define BG_PINK BACKGROUND_BLUE | BACKGROUND_RED | BACKGROUND_INTENSITY
// foreground attributes
#define FG_BLACK 0
#define FG_DARKGREY FOREGROUND_INTENSITY
#define FG_RED FOREGROUND_RED
#define FG_ORANGE FOREGROUND_RED | FOREGROUND_INTENSITY
#define FG_GREEN FOREGROUND_GREEN
#define FG_LIGHTGREEN FOREGROUND_GREEN | FOREGROUND_INTENSITY
#define FG_BLUE FOREGROUND_BLUE
#define FG_MEDIUMBLUE FOREGROUND_BLUE | FOREGROUND_INTENSITY
#define FG_GREY FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE
#define FG_WHITE FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY
#define FG_DARKORANGE FOREGROUND_RED | FOREGROUND_GREEN
#define FG_YELLOW FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY
#define FG_TEAL FOREGROUND_GREEN | FOREGROUND_BLUE
#define FG_LIGHTBLUE FOREGROUND_GREEN | FOREGROUND_BLUE | FOREGROUND_INTENSITY
#define FG_VIOLET FOREGROUND_BLUE | FOREGROUND_RED
#define FG_PINK FOREGROUND_BLUE | FOREGROUND_RED | FOREGROUND_INTENSITY
This is my first reply. Could somebody please tell me how to make code tags?


cya Gernot

[edited by - Gernot on December 4, 2002 12:59:02 PM]

Share this post


Link to post
Share on other sites

  • Advertisement