Message-ID: <383EE0F3.F1CD9F6A@arcticmail.com> From: N J Chackowsky X-Mailer: Mozilla 4.5 [en] (Win95; I) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: Colored Text References: <81jpar$p70$1 AT oak DOT prod DOT itd DOT earthlink DOT net> Content-Type: multipart/mixed; boundary="------------29BCA9261B77FFEEE9364FDB" Lines: 146 Date: Fri, 26 Nov 1999 19:32:35 GMT NNTP-Posting-Host: 206.45.76.75 X-Trace: typhoon.mbnet.mb.ca 943644755 206.45.76.75 (Fri, 26 Nov 1999 13:32:35 CST) NNTP-Posting-Date: Fri, 26 Nov 1999 13:32:35 CST Organization: MBnet Networking Inc. To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com This is a multi-part message in MIME format. --------------29BCA9261B77FFEEE9364FDB Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit The trouble with using conio.h is that you pretty much have to then use the printf family to make use of it. Here's a little .h file that allows you to use color fairly easily and still retain the standard cout << method of outputting in c++ I notice that Windows messed up the escape character. The first character in Ansi::background, for instance, is ALT-27, the left pointing arrow. =======snip======== /* ansi.h #include "ansi.h" to get three common ansi functions cout << clear(f, b) clear the screen cout << color(f, b) change text attributes cout << locate(r, c) move cursor to position (r,c) You must include the ANSI.SYS device driver in your CONFIG.SYS file. DOS/Win31: device=c:\dos\ansi.sys Win95: device=c:\windows\command\ansi.sys Would be more efficient if I'd used char[] instead of strings, but strings are so much EASIER to work with. */ #include namespace Ansi { string background = ""; string foreground = ""; string clearscreen = ""; string trans = "04261537"; string style = ""; string locator = ""; string digits = "0123456789"; string clear(int, int); string color(int, int); string locate(int, int); } string Ansi::locate(int r, int c) { Ansi::locator[3] = digits[r % 10]; Ansi::locator[2] = digits[r / 10]; Ansi::locator[6] = digits[c % 10]; Ansi::locator[5] = digits[c / 10]; return Ansi::locator; } string Ansi::clear(int f, int b) { Ansi::background[3] = Ansi::trans[b]; Ansi::foreground[3] = Ansi::trans[f]; return Ansi::style + Ansi::background + Ansi::foreground + Ansi::clearscreen; } string Ansi::color(int f, int b) { if (f > 15) f = 15; if (f < 0) f = 0; if (f > 7) { style[2] = '1'; f -= 8; } else style[2] = '0'; if (b > 7) b = 7; if (b < 0) b = 0; Ansi::foreground[3] = Ansi::trans[f]; Ansi::background[3] = Ansi::trans[b]; return Ansi::style + Ansi::foreground + Ansi::background; } /* Sample useage: #include #include #include #include #include "ansi.h" int main() { cout << Ansi::color(15,1) << "Here come some colors" << endl; cout << Ansi::color(14,2) << "Press a key to start" << endl; getch(); cout << Ansi::clear(7,0) << "Here is new test " << endl; for (int b=0; b < 8; b++) { for (int f=0; f < 16; f++) { if (f != b) cout << Ansi::color(f, b) << " This is a test." << endl; delay(200); } } } */ ============snap============ Michael Bronner wrote: > > Hi there! > I used to do some Turbo Pascal and GW Basic, and in those two languages it > was simple to output text in a colored format, to set the background and > foreground color of the text, etc. Can this be done in DJGPP C++ as well? > Thanks for your help! > > Sincerely, > Michael G. Bronner --------------29BCA9261B77FFEEE9364FDB Content-Type: text/x-vcard; charset=us-ascii; name="nick.vcf" Content-Transfer-Encoding: 7bit Content-Description: Card for N J Chackowsky Content-Disposition: attachment; filename="nick.vcf" begin:vcard n:Chackowsky;Nick tel;cell:204 729 6011 tel;fax:204 729 0365 tel;home:204 728 8184 tel;work:204 729 0363 x-mozilla-html:TRUE url:http://www.brandonsd.mb.ca/massey org:Vincent Massey High School;Business Education / Technology adr:;;715 McDiarmid Drive;Brandon;Manitoba;R7B 2H7;Canada version:2.1 email;internet:nick AT arcticmail DOT com title:Teacher fn:Nick J Chackowsky end:vcard --------------29BCA9261B77FFEEE9364FDB--