nielsew
asked on
Moving from a console app to a MFC windows app
I have just finished porting a unix app to a NT console app and would like to move it into a full MFC windows app.
Currently the NT console app displays graphics in one window (this window is being created by the graphics library) The other window is a console window in which the user enters commands.
I have set up an AppWiz generated program which will display my graphics as a view, but I am not sure how to handle creating another window to accept command line input\output. I think I will need to derive something from CEdit but after that I am lost.
I am very new to MFC programming, so any suggestions will be appreciated
-Eric
Currently the NT console app displays graphics in one window (this window is being created by the graphics library) The other window is a console window in which the user enters commands.
I have set up an AppWiz generated program which will display my graphics as a view, but I am not sure how to handle creating another window to accept command line input\output. I think I will need to derive something from CEdit but after that I am lost.
I am very new to MFC programming, so any suggestions will be appreciated
-Eric
ASKER
I understand dialogs to be an option, but I would rather find a way to direct stdin/stdout to a MFC window if this is possible. If you are familar will ClearCase Attache's interface, this is the type of "look" I am trying to create for my app. (ClearCase uses a splitter window with the bottom portion acting as a command line for user input/output)
Thanks,
-Eric
Thanks,
-Eric
There is an example in December 1997 issue of "Windows Developer's Journal" on a GUI+console application. I've got a code snippet:
(Simply call RedirectToConsole() at InitInstance() and a DOS window will be created. You can then use regular "cout >>", "cout <<", "printf", and "scanf".
-----GUICON.H-----
#ifndef _GUICON_H
#define _GUICON_H
#include <windows.h>
#include <wincon.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <iostream.h>
#include <fstream.h>
void RedirectIOToConsole();
#endif
// End of File
-----GUICON.CPP-----
#include "stdafx.h"
#include "GuiCon.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#ifndef _USE_OLD_IOSTREAMS
//using namespace std;
#endif
// Maximum number of lines the output console should have.
static const WORD MAX_CONSOLE_LINES = 500;
#define _GUICON_DEBUG
#ifdef _GUICON_DEBUG
void RedirectIOToConsole()
{
int hConHandle;
long hStdHandle;
CONSOLE_SCREEN_BUFFER_INFO conInfo;
FILE *fp;
// Allocate a console for this application.
AllocConsole();
// Set the screen buffer to be big enough to let us scroll text.
GetConsoleScreenBufferInfo (GetStdHan dle(STD_OU TPUT_HANDL E), &conInfo);
conInfo.dwSize.Y = MAX_CONSOLE_LINES;
SetConsoleScreenBufferSize (GetStdHan dle(STD_OU TPUT_HANDL E), conInfo.dwSize);
// Redirect unbuffered STDOUT to the console.
hStdHandle = (long)GetStdHandle(STD_OUT PUT_HANDLE );
hConHandle = _open_osfhandle(hStdHandle , _O_TEXT);
fp = _fdopen( hConHandle, "w" );
*stdout = *fp;
setvbuf( stdout, NULL, _IONBF, 0 );
// Redirect unbuffered STDIN to the console.
hStdHandle = (long)GetStdHandle(STD_INP UT_HANDLE) ;
hConHandle = _open_osfhandle(hStdHandle , _O_TEXT);
fp = _fdopen( hConHandle, "r" );
*stdin = *fp;
setvbuf( stdin, NULL, _IONBF, 0 );
// Redirect unbuffered STDERR to the console.
hStdHandle = (long)GetStdHandle(STD_ERR OR_HANDLE) ;
hConHandle = _open_osfhandle(hStdHandle , _O_TEXT);
fp = _fdopen( hConHandle, "w" );
*stderr = *fp;
setvbuf( stderr, NULL, _IONBF, 0 );
// Make cout, wout, cin, wcin, wcerr, cerr, wclog, and clog
// point to console as well.
// ios::sync_with_stdio();
}
#endif
// End of File
(Simply call RedirectToConsole() at InitInstance() and a DOS window will be created. You can then use regular "cout >>", "cout <<", "printf", and "scanf".
-----GUICON.H-----
#ifndef _GUICON_H
#define _GUICON_H
#include <windows.h>
#include <wincon.h>
#include <stdio.h>
#include <fcntl.h>
#include <io.h>
#include <iostream.h>
#include <fstream.h>
void RedirectIOToConsole();
#endif
// End of File
-----GUICON.CPP-----
#include "stdafx.h"
#include "GuiCon.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#ifndef _USE_OLD_IOSTREAMS
//using namespace std;
#endif
// Maximum number of lines the output console should have.
static const WORD MAX_CONSOLE_LINES = 500;
#define _GUICON_DEBUG
#ifdef _GUICON_DEBUG
void RedirectIOToConsole()
{
int hConHandle;
long hStdHandle;
CONSOLE_SCREEN_BUFFER_INFO
FILE *fp;
// Allocate a console for this application.
AllocConsole();
// Set the screen buffer to be big enough to let us scroll text.
GetConsoleScreenBufferInfo
conInfo.dwSize.Y = MAX_CONSOLE_LINES;
SetConsoleScreenBufferSize
// Redirect unbuffered STDOUT to the console.
hStdHandle = (long)GetStdHandle(STD_OUT
hConHandle = _open_osfhandle(hStdHandle
fp = _fdopen( hConHandle, "w" );
*stdout = *fp;
setvbuf( stdout, NULL, _IONBF, 0 );
// Redirect unbuffered STDIN to the console.
hStdHandle = (long)GetStdHandle(STD_INP
hConHandle = _open_osfhandle(hStdHandle
fp = _fdopen( hConHandle, "r" );
*stdin = *fp;
setvbuf( stdin, NULL, _IONBF, 0 );
// Redirect unbuffered STDERR to the console.
hStdHandle = (long)GetStdHandle(STD_ERR
hConHandle = _open_osfhandle(hStdHandle
fp = _fdopen( hConHandle, "w" );
*stderr = *fp;
setvbuf( stderr, NULL, _IONBF, 0 );
// Make cout, wout, cin, wcin, wcerr, cerr, wclog, and clog
// point to console as well.
// ios::sync_with_stdio();
}
#endif
// End of File
ASKER
Thanks!
I tried this out and it works well, but I would rather not allocate a console window. I would like the IO window to be embedded in the application window.
-Eric
I tried this out and it works well, but I would rather not allocate a console window. I would like the IO window to be embedded in the application window.
-Eric
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks again Mike.
This is just what I was looking for.
-Eric
This is just what I was looking for.
-Eric
My e-mail addtess is varghese_chacko@hotmail.co