Essential Difference between CONSOLE and GUI Applications



Click here for larger image

Environment: VC6 Win2K/NT/98

This sample describes the difference between CONSOLE and GUI applications with 20 lines of code.

There are 2 small projects in this sample. The first project shows how to create a console in WinMain(). First of all, we need to allocate a console with AllocConsole(); secondly, we in turn retrieve the operating system handle (GetStdHandle), run-time handle (_open_osfhandle), stream (_fdopen) and standard stream (stdout); finally, we can call functions like printf() and scanf().

The second project demonstrates how to create a window in main(). I created an edit box in a separate thread, so that you can control this window from the console. I retrieved the module handle through GetModuleHandle(), and then I called CreateWindow with the predefined class name EDIT.

As you can see, there is not much essential difference between console and GUI applications, even though VC requires us to indicate the type of the application when you create a project.

Downloads

Download demo project - 27 Kb
Download source - 4 Kb


Comments

  • Very usefull!

    Posted by Legacy on 02/10/2004 12:00am

    Originally posted by: Napo

    Thanks!

    Reply
  • Great!

    Posted by Legacy on 05/20/2003 12:00am

    Originally posted by: Benedikt

    I've tried to use the console for debug-information in a GUI program for some time now and didn't want to use an extra text field.
    Thanks a lot for this compact sample file :-)

    bye,
    Benedikt

    Reply
  • ? How could i retrieve the hwnd (wHandle) of console *.exe ?

    Posted by Legacy on 05/17/2002 12:00am

    Originally posted by: Riccardo Amati

    from R.Amati, Germany

    Hello everybody

    How could i retrieve the hwnd (windowHandle) of console *.exe ? I need to do an SDK showwindow(hide), but on sdk (or dosbox) it is showwindow(hwnd,hide). How could i retrieve the hwnd belonging to the window the *.exe is running in?

    Certainly, i could just pick all hwnd being a dos box and hiding them all ... but i want to hide just that one i am interested in (by pid?thread?). I tried these things suggested by the methods of CWinApp. All CWinApp.methods() return NULL whenver it comes to the point to retrieve dos box attributes.

    Any hint will be highly appreciated.

    Best regards


    • have u found it ?

      Posted by dharani on 08/31/2004 07:52am

      I am also trying to het HWND ( handle of console window ) . If u have done it pls tell me regds Dharani Babu S

      Reply
    Reply
  • How to discover at run time if the application is console or gui ?

    Posted by Legacy on 04/25/2002 12:00am

    Originally posted by: j. santana

    How to discover at run time if the application being run is a console application or a gui application ?

    Reply
  • Excellent

    Posted by Legacy on 12/29/2001 12:00am

    Originally posted by: xl

    Excellent

    Reply
  • Adding cout

    Posted by Legacy on 10/15/2001 12:00am

    Originally posted by: Thane

    The ostream cout can also be used in Gui.cpp by including the <iostream.h> header file and syncronizing with stdio.

    cout.sync_with_stdio();
    cout << "cout works too" << endl;

    Reply
  • Good!

    Posted by Legacy on 10/03/2001 12:00am

    Originally posted by: wolfbin

    I appreciate minimized code! ;)

    Reply
  • For all who cares about differences between gui and console app

    Posted by Legacy on 09/19/2001 12:00am

    Originally posted by: Vytukas

    /SUBSYSTEM:{CONSOLE|WINDOWS|NATIVE|POSIX|WINDOWSCE}[,major[.minor]]

    This option tells the operating system how to run the .EXE file. The subsystem is specified as follows:

    The CONSOLE subsystem is for a Win32 character-mode application. Console applications are given a console by the operating system. If main or wmain is defined, CONSOLE is the default.


    The WINDOWS subsystem applies to an application that does not require a console, probably because it creates its own windows for interaction with the user. Win32s operating systems can only run WINDOWS applications. If WinMain or wWinMain is defined, WINDOWS is the default.


    The NATIVE subsystem applies device drivers for Windows NT.


    The POSIX subsystem creates an application that runs with the POSIX subsystem in Windows NT.
    The optional major and minor version numbers specify the minimum required version of the subsystem. The arguments are decimal numbers in the range 0 through 65,535. The default is version 4.00 for CONSOLE, WINDOWS, and NATIVE; and version 19.90 for POSIX.

    The choice of subsystem affects the default starting address for the program. For more information, see the Entry-Point Symbol (/ENTRY:function) option.

    Reply
  • Can I start a MFC dialog box from a console program?

    Posted by Legacy on 09/17/2001 12:00am

    Originally posted by: shuo di

    I want to call a MFC dialog based application (generated by MFC AppWizard) from my console based program. What should I do?

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • QA teams don't have time to test everything yet they can't afford to ship buggy code. Learn how Coverity can help organizations shrink their testing cycles and reduce regression risk by focusing their manual and automated testing based on the impact of change.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds