25 Years of Programming
An open source source for C, C++, OWL, BASIC, MDB, XLS, DOT, and more...
Home   Projects   Up   Sitemap   Search   Blog   Forum+Chat   About Us   Privacy   Terms of Use   Feedback   FAQ   Images   Services   Ads   Donate   Humor

Functions in Borland C++ for MSDOS or EasyWin

A note about EasyWin:

The Borland C++ 4.0 User's Guide, page 407, says that you can also initialize and use an EasyWin console in a "true" Windows (e.g. OWL) program. I tried on and off for nearly two years to make this work, spending many days trying to track down what was missing. It turned out to be simple (arrgh!): to use EasyWin, your project must be static linked. The EasyWin code is only in the static link libraries.

yesno.cpp

/*	yesno.cpp		12-2-96
	Copyright (C)1996 Steven Whitney.
	Published under GNU GPL (General Public License) Version 2, with ABSOLUTELY NO WARRANTY.

	Asks user a yes/no question, using either cout or a provided constream.
	returns TRUE if the answer is yes, FALSE if no.

	prompt is a string, not a string&, so it can have a default value (see my.h)

*/
#include <conio.h>
#include "c:\bcs\my.h"

BOOL yesno(string prompt, ostream& os)
{
	int ch;
	os << endl;
	do
	{
		os << prompt << " (y/n)? ";
		ch = tolower(getche());
		os << endl;
	}
	while((ch != 'y') && (ch != 'n'));
	return(ch == 'y');
}

presskey.cpp

/*	presskey.cpp				12-19-96
	Copyright (C)1996 Steven Whitney.
	Published under GNU GPL (General Public License) Version 2, with ABSOLUTELY NO WARRANTY.
	says press any key to continue, and waits for a key.  erases its message
	to leave a cleaner screen, but moves to new line anyway so that
	if echoed to printer with ^P, subsequent text won't overwrite.

	The default os is cout, but can be, for example, a constream.
	12-2-99 returns the char you pressed so it can be used.
*/
#include <stdio.h>
#include <conio.h>
#include "c:\bcs\my.h"

int presskey(ostream& os)
{
	os << "Press any key to continue...";
	int ch = getch();
	os << "\r                            " << endl;
	return(ch);
}

aborts.cpp

/*	aborts.cpp				10-31-96
	Copyright (C)1996 Steven Whitney.
	Published under GNU GPL (General Public License) Version 2, with ABSOLUTELY NO WARRANTY.

	prints a specified error message and aborts program execution
	"plain" version.  see graborts() for version that calls closegraph().

	Advantage of this over BC4 abort() is that this will cause destructors
	to be called for all objects, while abort() calls NO destructors, not
	even for globals (PG:147). Any open fstreams are closed by their destructors.

*/
#include <stdio.h>
#include <stdlib.h>
#include "c:\bcs\my.h"

void aborts(const string& s)
{
	cerr << endl << s << endl;
	presskey();        			// prevent msg scrolling off before being seen
	exit(1);
}

 

 

Valid HTML 4.01 Transitional Valid CSS
View content labeling at ICRA.
Copyright ©2007 Steven Whitney. Last modified 09/25/2007.