Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a Modeless Messagebox

Tags:

How might one go about creating a Modeless MessageBox? Do I have to just create my own Windows Form class and use that? If so, is there an easy way of adding a warning icon (rather than inserting my own image of one) and resizing based on text volume?

like image 428
Smashery Avatar asked Jun 17 '10 06:06

Smashery


People also ask

How do I create a modal dialog box in MFC?

To create a modal dialog box, call either of the two public constructors declared in CDialog. Next, call the dialog object's DoModal member function to display the dialog box and manage interaction with it until the user chooses OK or Cancel. This management by DoModal is what makes the dialog box modal.

How do I create a dialog box in win32?

You create a modal dialog box by using the DialogBox function. You must specify the identifier or name of a dialog box template resource and a pointer to the dialog box procedure. The DialogBox function loads the template, displays the dialog box, and processes all user input until the user closes the dialog box.

What is a modeless dialog box?

Modal dialog boxes, which require the user to respond before continuing the program. Modeless dialog boxes, which stay on the screen and are available for use at any time but permit other user activities.

How do you create a dialog box in Windows?

To create a new dialog box In Resource View, right-click your . rc file and select Add Resource. In the Add Resource dialog box, select Dialog in the Resource Type list, then choose New. If a plus sign (+) appears next to the Dialog resource type, it means that dialog box templates are available.


2 Answers

If you need a message box that just displays itself while your code continues running in the background (the box is still modal and will prevent the user from using other windows until OK is clicked), you can always start the message box in its own thread and continue doing what ever you do in the original thread:

    // Do stuff before.     // Start the message box -thread:     new Thread(new ThreadStart(delegate     {       MessageBox.Show       (         "Hey user, stuff runs in the background!",          "Message",         MessageBoxButtons.OK,         MessageBoxIcon.Warning       );     })).Start();     // Continue doing stuff while the message box is visible to the user.     // The message box thread will end itself when the user clicks OK. 
like image 121
tojotamies Avatar answered Sep 28 '22 11:09

tojotamies


You'll have to create a Form and use Show() to display it Modeless. MessageBox.Show(...) behaved Modal as seen in the example by ghiboz; "Description of the message" is displayed until the user presses a button.

With MessageBox.Show(...) you get the result as soon as the messagebox is closed; with a modeless message box, your code will have to have a mechanism such as an event to react when the user eventually selects something on your message box.

like image 35
John Warlow Avatar answered Sep 28 '22 09:09

John Warlow