Creare messagebox in c e gtk2

Autore: Fabio Di Matteo
Ultima revisione: 24/01/2010

Ecco 3 funzioni che creano 3 message box una di info, una di conferma e l'altra d'errore: (come argomenti vogliono la finestra principale del programma che li genera e il testo del messaggio)

static void
info_message(main_window,messaggio)
{
  GtkWidget *dialog;
 
  	dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (main_window),
				   GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
				   GTK_MESSAGE_INFO,
				   GTK_BUTTONS_OK,
				   "<span size=\"x-large\"><b>Info:</b></span>");
	gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
					(gchar *)messaggio);
	gtk_window_set_title(GTK_WINDOW(dialog),"Information");
  	gtk_dialog_run (GTK_DIALOG (dialog));
  	gtk_widget_destroy (dialog);
}
 
 
static gint
info_YesNo(main_window,messaggio)
{
  GtkWidget *dialog;
  gint result;
 
  	dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (main_window),
				   GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
				   GTK_MESSAGE_WARNING,
				   GTK_BUTTONS_YES_NO,
				   "<span size=\"x-large\"><b>Warning:</b></span>");
	gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
					(gchar *)messaggio);
	gtk_window_set_title(GTK_WINDOW(dialog),"Warning");
  	result = gtk_dialog_run (GTK_DIALOG (dialog));
	switch (result)
    {
      case GTK_RESPONSE_YES:
         result=GTK_RESPONSE_YES ;
		 break;
	  case GTK_RESPONSE_NO:
         result=GTK_RESPONSE_NO ;
		 break;	 
 
      default:
         result=GTK_RESPONSE_DELETE_EVENT;
         break;
    }
  	gtk_widget_destroy (dialog);
	return result;
 
}
 
static void
err_message(main_window,messaggio)
{
  GtkWidget *dialog;
 
  dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (main_window),
				   GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
				   GTK_MESSAGE_ERROR,
				   GTK_BUTTONS_OK,"<span size=\"x-large\"><b>Error:</b></span>");
  gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),
  												(gchar *)messaggio);
  gtk_window_set_title(GTK_WINDOW(dialog),"Error");
  gtk_dialog_run (GTK_DIALOG (dialog));
  gtk_widget_destroy (dialog);
}

Navigazione

..::FreeMediaLab::..


   Indice wiki
   Home Wiki

   

   



Donazioni

Tools personali