Solved

Are popup dialog boxes with a console app possible?

Posted on 1998-10-02
1
477 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 8

Accepted Solution

by:
Answers2000 earned 100 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
sum67 challenge 35 116
has22 challenge 11 107
sum28 challenge 31 117
Authenticate using sesu from script 7 111
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

749 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