Solved

Are popup dialog boxes with a console app possible?

Posted on 1998-10-02
1
465 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
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Change owner from userA to server Local Administrators 7 66
Smart Camera scanning and reading information 3 114
wordmultiple challenge 12 142
SQUD PROXY SERVER, UNIX, SLL/HTTPS 5 104
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…
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

828 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