[OT - Win32 Screen Control] Re: Q: Example of ANSI Screen Control Code Use?
From: Anthony Borla (ajborla_at_bigpond.com)
Date: Wed, 30 Mar 2005 05:13:23 GMT
"Neil - Salem, MA USA" <Neil@Salem.Massachusetts.USA> wrote in message
> "r norman" <rsn_@_comcast.net> wrote in message
> > On Tue, 29 Mar 2005 12:47:10 -0500, "Neil - Salem, MA USA"
> > <Neil@Salem.Massachusetts.USA> wrote:
> >>I am so new to C++ that most newbies are experts by
> >> comparison. (But...give me a year and I will hopefully begin to
> >> be competent. I have 12 excellent books, recommended by
> >> folks on comp.lang.c++.moderated, that I am, and will be,
> >> reading.) That said, forgive my question if it has been
> >>asked and answered before.
I believe that just about all questions - including those wanting to know
the secret of Life, the Universe and Everything - have been asked ;) !
> >>Since there is only basic support for screens in C++, how
> >> can I create ANSI color screens using ANSI screen control
> >> codes? Can someone direct me to a good, yet simple,
> >> example? I will be running my C++ program in a DOS
> >>windowon a Windows XP system. Will I need a driver
> >> like ansi.sys?
Actually, it is really quite simple to make use of ANSI screen control
codes - just print them out along with your text output ! Example:
const char ESC = '\033';
void gotoXY(int x, int y)
std::cout << ESC << y << ';' << x << 'H << std::flush;
std::cout << ESC << "2J" << std::flush;
However, the problem isn't using them, but finding ANSI support on modern
systems. Put simply, if you're targeting older systems like MS-DOS 6.xx, or
MS Windows 3.xx - 98, then all you need is to install the ANSI.SYS driver.
For later systems [and you mentioned WinXP] there *may* be third party
ANSI.SYS drivers available [for download or purchase]. However, these are
certainly not 'standard items' anymore, thus this may not be a viable
development approach anymore [assuming you are not simply doing so for hobby
or learning purposes. If so, then go for it, unless you find something
better :) !].
> > I most strongly urge you to reconsider your strategy. The
> > ANSI screen control codes were very useful for a period
> > of time that is long past. There are now far more sophisticated
> > screen display systems that are far more useful and desirable
> > if you want to make useful programs.
> Please tell me what these "far more sophisticated screen
> display systems" are.
Given my explanation you should now have a clearer context for the advice 'r
norman' gave you. It certainly shouldn't be taken as a 'put down' or 'brush
off', merely a description of the current state of the art.
> > True, there is no support in the basic C++ language
> > for windowed or graphical user interface programming.
> > But that doesn't mean you should do that using tools
> > available through your compiler or operating system.
> > If you really do want to write plain, vanilla "console" type
> > programs that write to cin and cout (or stdin and stdout
> > in C),
> and I don't ...that's why I wrote my question ...
Sure, but while these are 'primitive' in user interface terms, they *are*
portable. However, I agree with you, it is a fairly unrealistic stance. The
aim should be to write software that meets specific requirements. Developing
it with an eye on portability issues may simplfiy this task if it is ever to
be ported in future, and to be quite honest, it is far more common these
days where there seems to be a growing requirement that at least some
software operate under both Win32 and *NIX.
> > then just
> > concentrate on plain, vanilla text output.
> I'm sorry ...but I thought I was clear about the fact that I
> was hoping to go beyond "plain, vanilla text output."
Well, your need is for a third party library, be it a collection of
screen-handling / windowing functions, or something more OOP-ish - an
screen-management framework. Starting at the primitive end, you could
directly use the Win32 Console API. Your compiler should allow you to
include the <windows.h> header, and you'll have direct access to all Console
A Google search should turn up:
* Examples of Console API use
* Third Party Libraries / Framworks based on this API;
these would generally be much easier to use
One such library that actually has an eye on portability is the 'ncurses'
library. It originally hailed on *NIX systems where it was very popular, and
has been ported to many systems including OpenVMS and Win32. Again, a Google
search should turn up one or more suitable implementations.
> > To be more specific, the ANSI control codes were developed
> > for use by "smart" terminals, peripheral devices used to interface
> > with computers in the "good old days". The ANSI sys driver
> > used by DOS was a way of making the PC running DOS
> > emulate a terminal. OK, it may be that you really do have to
> > write software to support such a terminal. Unless that is true,
> > though, I suggest you develop your skills in other directions.
> I'm sorry ...but what "directions" are you talking about?
GUI's, I believe. Personally, I prefer coding these using scripting
languages - much, much easier to do !
> I welcome all helpful responses,
Let's hope mine 'makes the grade' :) !