Essential Difference between CONSOLE and GUI Applications


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

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.


Download demo project - 27 Kb
Download source - 4 Kb


  • Very usefull!

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

    Originally posted by: Napo


  • Great!

    Posted by Legacy on 05/20/2003 07: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 :-)


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

    Posted by Legacy on 05/17/2002 07: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 02:52pm

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

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

    Posted by Legacy on 04/25/2002 07: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 ?

  • Excellent

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

    Originally posted by: xl


  • Adding cout

    Posted by Legacy on 10/15/2001 07: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 << "cout works too" << endl;

  • Good!

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

    Originally posted by: wolfbin

    I appreciate minimized code! ;)

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

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

    Originally posted by: Vytukas


    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.

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

    Posted by Legacy on 09/17/2001 07: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?

  • You must have javascript enabled in order to post comments.

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

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date