Can create but can't write to MFC GUI console

Can create but can't write to MFC GUI console

Post by Todd Jelle » Tue, 22 Apr 1997 04:00:00



I've developed a C++ Delaunay/Voronoi triangulation library which runs
fine on several flavors of Unix as well as NT and Win95 console
applications. The debug version of the library writes error and
diagnastic information to STDOUT and STDERR as formatted text through
cout and cerr.

Now I have an MFC GUI application to visualize the triangulations. I
want to be able to allocate a console and have the diagnostic output
from the triangulation library go to the console window without having
to modify the library (so it still runs on Unix).

The application is a standard MFC Doc/View app created with AppWizard.
I can create the console window using AllocConsole()  ( in
InitInstance() in the App ), but nothing gets written to it.

I tried to redirect STD_OUTPUT_HANDLE and STD_ERROR_HANDLE using
SetStdHandle() but can't seem to get a handle to the newly created
console's standard output and standard error. The docs for
CreateFile() say to use CON and CONOUT&. What the hell are they? I
grepped and searched for these but turned up nothing. What's going on
here?

I noticed that before I created the console, GetStdHandle() returned 0
(no stdout) and after the call to AllocConsole() it was 7 (0x00000007)
Is this a valid handle? (Doesn't work if it is!)

What am I doing wrong? Am I going about this all wrong? Should I be
using CreateProsess() instead?

Any help would be appreciated.

Thanks
Todd
--
**********************************************************************
Todd Jellett                                Phone : (506) 453-4530        
Manager GIS Laboratory                      Fax   : (506) 453-5055          
Dept. of Geology                                                            

Fredericton, N.B.
Canada  E3B 5A3
**********************************************************************

 
 
 

1. Killing a console window created using AllocConsole() in an MFC GUI app

Hello all,

There have been numerous postings about how to use printf() and cout
in the context of a GUI application.  I have done such a thing in my
application, but I seem to have run into a stumbling block.  I have a
menu item that hides or shows my "log" window, which is nothing more
than a console created via AllocConsole().  Now what happens is if the
user closes the console window by clicking on the "x marks the spot
close area" up there in the upper right-hand corner my entire
application exits!  I would prefer to prevent this from occurring,
either one of two ways:

(a) Is there some Windows configuration that prevents the
minimize/maximize/close title-bar areas from appearing in console
windows?  Barring that, is there something in AllocConsole() or the
related console API that will prevent these from appearing?  Is there
a windows hook method I could use?

(b) Is there a way to catch the close event occurring, and then
perhaps re-AllocConsole() a new console?

To provide some more context, my MFC app spins off a little thread
that calls AllocConsole.  In this thread I use the FindWindow() Win32
function to grab and store an HWND, which I subsequently use to
hide/show the window depending on GUI menu callbacks.  My thread proc
is quite simple :

while (m_bRunning)

  WriteFile(hConOut, ...);

FreeConsole();

Of course, I've tried setting a breakpoint in a destructor, which sets
m_bRunning to FALSE, and then closed my console window.  The entire
application still terminates and the debugger never hits the
breakpoint.

Any help/advice would be most appreciated.  I really don't want to
slap together a GUI entity that shuttles STDOUT and STDERR onto a rich
text-edit control.

-Shehrzad

2. video capture cards

3. Canned emails

4. Floppy Disk Spins When Launch IE.

5. cans shut down only restart

6. FAT32 to NTFS with 4k cluster

7. MS Replies to mt Intellipoint 5.0 request - not a canned reply!!!

8. voice activation

9. ASP email program - canned

10. Canned Air Cleaner

11. Data entry w/ canned comments

12. Can lib calls using cout/iostream be redirected to MFC GUI console?

13. Console style app using MFC and Windows GUI