MessageDialog presents a dialog with some message text.
It’s simply a convenience widget; you could construct the equivalent of MessageDialog from Dialog without too much effort, but MessageDialog saves typing.
One difference from Dialog is that MessageDialog sets the skip_taskbar_hint property to true, so that the dialog is hidden from the taskbar by default.
The easiest way to do a modal message dialog is to use run, though you can also pass in the gtk_dialog_modal flag, run automatically makes the dialog modal and waits for the user to respond to it. run returns when any dialog button is clicked.
An example for using a modal dialog:
GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
dialog = gtk_message_dialog_new (parent_window,
flags,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Error reading “%s”: %s",
filename,
g_strerror (errno));
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
u might do a non-modal MessageDialog as follows:
An example for a non-modal dialog:
GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT;
dialog = gtk_message_dialog_new (parent_window,
flags,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"Error reading “%s”: %s",
filename,
g_strerror (errno));
// Destroy the dialog when the user responds to it
// (e.g. clicks a button)
g_signal_connect_swapped (dialog, "response",
G_CALLBACK (gtk_widget_destroy),
dialog);
GtkMessageDialog as GtkBuildable
The GtkMessageDialog implementation of the GtkBuildable interface exposes the message area as an internal child with the name “message_area”.