Advertisement

ASCII iColored n C/C++ URGENT!

Started by December 01, 2002 11:21 PM
14 comments, last by ElPeque 21 years, 11 months ago
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
"Be forgotten is worse than death..."[email=rgdonato@gmail.com]Rafael G. Donato[/email]
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 ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
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_GREENSetConsoleTextAttribute(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;  
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_GREENSetConsoleTextAttribute(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;  
quote: Original post by Fruny
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
"Be forgotten is worse than death..."[email=rgdonato@gmail.com]Rafael G. Donato[/email]
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]
cya Gernot

This topic is closed to new replies.

Advertisement