Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Moving from a console app to a MFC windows app

Posted on 1998-04-07
6
Medium Priority
?
279 Views
Last Modified: 2013-11-20
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

0
Comment
Question by:nielsew
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Expert Comment

by:chacko
ID: 1317511
You can use dialogs for getting the input. You need to design the UI very neatly so that it takes less pain to write in MFC and neat. If you send the details of the project I can help you out

My e-mail addtess is varghese_chacko@hotmail.com

0
 

Author Comment

by:nielsew
ID: 1317512
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


0
 
LVL 4

Expert Comment

by:tflai
ID: 1317513
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(GetStdHandle(STD_OUTPUT_HANDLE), &conInfo);
    conInfo.dwSize.Y = MAX_CONSOLE_LINES;
    SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), conInfo.dwSize);

    // Redirect unbuffered STDOUT to the console.
    hStdHandle = (long)GetStdHandle(STD_OUTPUT_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_INPUT_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_ERROR_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
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:nielsew
ID: 1317514
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
0
 
LVL 11

Accepted Solution

by:
mikeblas earned 400 total points
ID: 1317515
Use a static splitter window. In the first pane, set up your graphics view.  In the second pane, use a CEditView. In the CEditView, respond to the EN_UPDATE message so you know each time the user enters a character (including a carriage return).

.B ekiM
0
 

Author Comment

by:nielsew
ID: 1317516
Thanks again Mike.
This is just what I was looking for.

-Eric
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question