1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| #include <gtk/gtk.h>
static void hello(GtkWidget *widget, gpointer data);
static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer data);
static void destroy(GtkWidget *widget, gpointer data);
int main(int argc, char *argv[])
{
GtkWidget *maFenetre;
GtkWidget *monBouton;
GtkWidget *monLabel;
gtk_init (&argc, &argv);
maFenetre = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(maFenetre), "ma fenêtre");
gtk_window_set_default_size(GTK_WINDOW(maFenetre), 300, 300);
g_signal_connect(maFenetre, "delete-event", G_CALLBACK(delete_event), NULL);
g_signal_connect(maFenetre, "destroy", G_CALLBACK(destroy), NULL);
monBouton = gtk_button_new_with_label("fermer");
g_signal_connect(monBouton, "clicked", G_CALLBACK(hello), NULL);
g_signal_connect_swapped(monBouton, "clicked", G_CALLBACK(gtk_widget_destroy), maFenetre);
monLabel=gtk_label_new("Salut à tous.\nMerci pour votre aide.");
gtk_label_set_justify(GTK_LABEL(monLabel), GTK_JUSTIFY_LEFT);
gtk_container_add(GTK_CONTAINER(maFenetre), monLabel);
gtk_container_add(GTK_CONTAINER(maFenetre), monBouton);
gtk_widget_show(monLabel);
gtk_widget_show(monBouton);
gtk_widget_show(maFenetre);
gtk_main ();
return 0;
}
static void hello(GtkWidget *widget, gpointer data){g_print("boutton\n");}
static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer data){g_print ("fermeture\n"); return FALSE;}
static void destroy(GtkWidget *widget, gpointer data){gtk_main_quit();} |
Partager