🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #8020

Re: Console Window for GUI application

#8020
From: Bob Gonder
Date: Tue, 07 Dec 2004 19:46
86 lines
3676 bytes
Richard Ulrich wrote:

>I recently converted a commandline application to a GUI application.
>Now it would be nice to display all the cout's in a commandline window 
>for debugging purposes.
>
>It opens that commandline window, and I don't get any errormessages, but 
>it doesnt' print out any of the cout's. Also printf doesn't write to 
>that commandline window.
>
>Any hints?
>Richard
>
>And here's the code:
>
>class DebugConsole
>{
>     public:
>         DebugConsole();
>         ~DebugConsole();
>
>     private:
>         bool	m_exists;
>};

One wonders why your DebugConsole class doesn't have display
functions?

	DebugConsole Console = new DebugConsole(80,500);
	Console.Print("Error#123\n\r");
	Console<<"Error#"<<123<<endl;

>DebugConsole::DebugConsole()
>{
>     int ret;
>	m_exists = ::AllocConsole() != 0;

	Change m_exists to BOOL, then you can do
	m_exists = ::AllocConsole();

>	if(!m_exists)
>		::MessageBox(0, "Couldn't create debug console!", "Error", 
>MB_ICONERROR | MB_OK);

	You don't exit on error

>	CONSOLE_SCREEN_BUFFER_INFO coninfo;
>	::GetConsoleScreenBufferInfo(::GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
>	coninfo.dwSize.Y = 500;
>	::SetConsoleScreenBufferSize(::GetStdHandle(STD_OUTPUT_HANDLE), 
>coninfo.dwSize);
>
>	// redirect unbuffered STDOUT to the console
>	intptr_t	pStdHandle = 
>reinterpret_cast<intptr_t>(::GetStdHandle(STD_OUTPUT_HANDLE));
>	int			hConHandle = _open_osfhandle(pStdHandle, _O_TEXT);
>	FILE* pFile = _fdopen(hConHandle, "w");
>	*stdout = *pFile;
>	ret = setvbuf(stdout, NULL, _IONBF, 0);

I don't think that's right (but I could be wrong)
Here's what I do in a pure console app (but then, I don't use cout,
printf, etc because I want total control):

/*	Global values	*/
HANDLE	stdout = INVALID_HANDLE_VALUE;

/*	Startup		*/
	stdout=GetStdHandle(STD_OUTPUT_HANDLE);
	SetConsoleMode(stdout,ENABLE_PROCESSED_OUTPUT);
	GetConsoleScreenBufferInfo( stdout, &sbi );
	sbi.dwSize.Y = 500;	/* just for you */
	SetConsoleScreenBufferSize(stdout, sbi.dwSize);

/*	Usage		*/
	WriteFile( stdout,cstring,length,&byteswritten,NULL);

You can wrap that any way you want. I wrote a cputs() that massages
the data before passing it on. You could write a string stream
interface that masages stream data into output strings.


>	// redirect unbuffered STDIN to the console

Why bother with stdin or stderr for a debug console?
All input should be through the GUI, no?
Technical Details
Message-ID: <j6vbr0djl2alcs374q8q9su4vd6u88liqb@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!newsprint.newsread.com!newsfeed00.sul.t-online.de!t-online.de!news.zanker.org!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <41b5d8dc@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,29bc3d9d57e77864
X-Google-Attributes: gid10cc67,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.nativeapi
Subject: Re: Console Window for GUI application
Date: Tue, 07 Dec 2004 11:46:44 -0800
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <j6vbr0djl2alcs374q8q9su4vd6u88liqb@4ax.com>
References: <41b5d8dc@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 67.77.36.100
X-Trace: newsgroups.borland.com 1102448802 67.77.36.100 (7 Dec 2004 11:46:42 -0800)
Lines: 88
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!newsread.com!newsprint.newsread.com!newsfeed00.sul.t-online.de!t-online.de!news.zanker.org!feeder.enertel.nl!nntpfeed-01.ops.asmr-01.energis-idc.net!216.196.110.149.MISMATCH!border2.nntp.ams.giganews.com!nntp.giganews.com!pe2.news.blueyonder.co.uk!blueyonder!news-peer-test!btnet!newsfeed.bt.es!caladan.landsraad.net!newsgroups.borland.com!not-for-mail