Toggle between Console/GUI mode

I have a MFC application.I would like to be able to toggle between the GUI mode and Console mode.I have
figured out how to open a Console,but now when I run the application it simulataneously opens a Console as well.
Is it possible to have a button so that the Console would open only when I desire?
Also how I can use all the functionalities in my application from the console,right now only ctrlC works!
Thank you for any help and suggestions.
samroycAsked:
Who is Participating?
 
jkrConnect With a Mentor Commented:
>>Is it possible to have a button so that the Console would open only when I desire?

Sure, just make sure to 'manually' call 'AllocConsole()'. Then use

   int hCrt;
   FILE *hf;

   AllocConsole();
   hCrt = _open_osfhandle(
             (long) GetStdHandle(STD_OUTPUT_HANDLE),
             _O_TEXT
          );
   hf = _fdopen( hCrt, "w" );
   *stdout = *hf;
   i = setvbuf( stdout, NULL, _IONBF, 0 );
                        
to access the console window.

Check out http://support.microsoft.com/default.aspx?scid=kb;en-us;105305 ("INFO: Calling CRT Output Routines from a GUI Application")
0
 
AxterCommented:
Hi samroyc,
What is your motivation behind this?

David Maisonave :-)
Cheers!
0
 
samroycAuthor Commented:
the application will be run by users remotely to control a device.I need to be able to get to the controls using console,
as a "superuser",just in case somethings go wrong or the prg crashes while communicating with the device etc...
So I need an option where in the console is also available.
Thanks
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
AxterCommented:
>>So I need an option where in the console is also available.

Do you want this option when the program first starts up, or after there's a display?

IMHO, it would be better for a super user to have this feature via a special super user GUI window.
0
 
samroycAuthor Commented:
After a display is fine.
**IMHO, it would be better for a super user to have this feature via a special super user GUI window.**
I am not sure if I uderstand what this means,another application,or just another control button that opens
another window?
Thank you for your interest.
 
 
   
 
0
 
AxterCommented:
>>I am not sure if I uderstand what this means,another application,or just another control button that opens
>>another window?

Check out the following link:
http://www.codeguru.com/Cpp/controls/controls/coolcontrols/article.php/c8589/

The above project is an example of using a GUI window to enter command lines, like you would in console mode.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.