Solved

Are popup dialog boxes with a console app possible?

Posted on 1998-10-02
1
423 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 100 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Perl Awk Need Help 3 94
has22 challenge 11 71
abstract class with all non abstract mentods 6 71
Detect file exist or not 3 76
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now