Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I do console output in MFC GUI app?

Status
Not open for further replies.

GEAK

Instructor
Feb 1, 2001
90
US
I've written a dialog-based, MFC application. The program performs one of three different tasks. The bulk of the code exists in the app class and is called from the dialog class. I've also got the program set up so that command line arguments are parsed and if provided, the tasks are executed without displaying the dialog.
e.g.
To display the dialog: AppName.exe
To execute task #1: AppName.exe /1
To execute task #2: AppName.exe /2 switch
To execute task #3: AppName.exe /3 value path

The arguments are being parsed in the app class' InitInstance function. I'd like to add a fifth option which is AppName.exe /? and it would display brief instructions but I have no idea how to do console output from the app class.
Is there an MFC or Win32 call that'll give me a pointer to/handle of the console window? Is there some other way of directing output to the command window that is used to launch your app? I've got code archived somewhere that'll create a console window but that isn't what I want.
 
Something like this
Code:
void CMFCTestView::OnOuch()
{
   static HANDLE out;  // This can be part of the class

   // This can be part of the application initialization
   if (AllocConsole ())
   {
      out = GetStdHandle (STD_OUTPUT_HANDLE);
   }

   // printfs don't work - you have to use writeconsole
   CString dump = "Ouch\n";
   DWORD written;
   WriteConsole (out, (LPCTSTR) dump, dump.GetLength(), &written, 0);
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top