### Tutorial
« Dialogs | Menu Items »

## MessageDialog

A message dialog is a dialog with an image representing the type of message (Error, Question, etc.) alongside some message text. It's simply a convenience widget; you could construct the equivalent of Gtk::MessageDialog from Gtk::Dialog without too much effort, but Gtk::MessageDialog saves typing.
The easiest way to do a modal message dialog is to use Gtk::Dialog::run(), though you can also pass in the Gtk::DIALOG_MODAL flag, Gtk::Dialog::run() automatically makes the dialog modal and waits for the user to respond to it. Gtk::Dialog::run() returns when any dialog button is clicked.
To create a MessageDialog call one of the following constructors:

`MessageDialog(Gtk::MessageType type, Gtk::ButtonType buttons, Gtk::Window *parent = 0, Gtk::DialogFlagsField flags = Gtk::DIALOG_DESTROY_WITH_PARENT); MessageDialog(Gtk::MessageType type, Gtk::ButtonType buttons, const String& message, Gtk::Window *parent = 0, Gtk::DialogFlagsField flags = DIALOG_DESTROY_WITH_PARENT);`

The first constructor creates a message dialog with no message. If you use this constructor you will need to explicitly call set_message(). The second constructor sets all the fields at construction, including the message.
The type argument is the message type and can be one of the following values in the Gtk::MessageType enumeration:

- MESSAGE_INFO
- MESSAGE_WARNING
- MESSAGE_QUESTION
- MESSAGE_ERROR

The buttons argument is the set of buttons to display in the dialog and can be one of the following values in the Gtk::ButtonType enumeration:

- BUTTONS_NONE
- BUTTONS_OK,
- BUTTONS_CLOSE
- BUTTONS_CANCEL
- BUTTONS_YES_NO
- BUTTONS_OK_CANCEL

The parent argument specifies the transient parent for the dialog and the flags argument the dialog flags. The dialog flags can can be one or more of the following values from the Gtk::DialogFlags enumeration OR'd together.

- DIALOG_MODAL
- DIALOG_DESTROY_WITH_PARENT - the default flag
- DIALOG_NO_SEPARATOR

To set the message text call one of the following methods:

`void set_message(const String& message); void set_message(const char *message_format, ...);`

The first method set the message text from a String. The second method sets the message text from a character string formatted inline using sprintf-style formatting.
To display a modal message dialog call the Gtk::Dialog method:

`int run();`

For example, this is a message dialog from appwindow.cc in the inti-demo source code.

`Gtk::MessageDialog *dialog(Gtk::MESSAGE_INFO, Gtk::BUTTONS_CLOSE, this); dialog->set_message("You selected or toggled the \"%s\" menu item: \"%s\"", parent, item); if (dialog->run()) dialog->dispose();`

« Dialogs | Index Miscellaneous Widgets Top | Menu Items »