Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Are popup dialog boxes with a console app possible?

Posted on 1998-10-02
1
Medium Priority
?
517 Views
Last Modified: 2013-11-20
I'm wrestling with a programming request to spawn popup dialog boxes from a previously written console program. I not sure if this is possible as console programs can't handle most USER and GDI functions (ie. Windows, brushes, menus, etc.). If you know a way around this, please respond.
0
Comment
Question by:gmacgougan
1 Comment
 
LVL 8

Accepted Solution

by:
Answers2000 earned 300 total points
ID: 1322873
Yes you can, but you may not be able to use MFC to do it.

In a Win32 console program you can call just about any Windows API call.  For a dialog box you can create one use the Windows API using DialogBox function call.

For the parent window pass NULL or GetFocus()

The main (relevant) difference between Win32 console programs and Win32 GUI programs is you don't have a message loop.  Fortunately if you use DialogBox to create a modal dialog box, Windows includes a message loop which operates while the dialog box is displayed.

You should note that
1. If you use the MFC CDialog and DoModal function to do this it probably won't work as MFC infrastructure for GUI programs won't have been set up (it's okay to use other MFC functions in the same program though for example CString class)

2.  The dialog box you write should use a dialog box CALLBACK function.  You can cut and paste this from one of the SDK samples.

3. For maximum flexibility the main alternative is to create your GUI elements in a separate process compiled as a GUI program.  You main program can then use CreateProcess to invoke them and WaitForSingleObject to wait for these processes to terminate.  If you use this approach you can do just about anything from your console program, though for simply displaying a dialog it isn't necessary

I have seen a number of console programs which pick a file name use a GUI dialog box.  The GetOpenFileName API is used for this, but for the more general case modal dialog boxes created with DialogBox API is quite okay
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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
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.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Suggested Courses

886 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