main.c (1616B)
1 #include <gtk/gtk.h> 2 #include <stdlib.h> 3 4 static void print_hello (GtkWidget *widget, gpointer data) { 5 g_print ("Hello World\n"); 6 } 7 8 GdkPixbuf *create_pixbuf(const gchar * filename) { 9 10 GdkPixbuf *pixbuf; 11 GError *error = NULL; 12 pixbuf = gdk_pixbuf_new_from_file(filename, &error); 13 14 if (!pixbuf) { 15 16 fprintf(stderr, "%s\n", error->message); 17 g_error_free(error); 18 } 19 20 return pixbuf; 21 } 22 23 static void activate (GtkApplication *app, gpointer user_data) { 24 GtkWidget *window; 25 GtkWidget *button; 26 GtkWidget *button_box; 27 28 window = gtk_application_window_new (app); 29 gtk_window_set_title (GTK_WINDOW (window), "Window"); 30 gtk_window_set_default_size (GTK_WINDOW (window), 200, 200); 31 32 button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL); 33 gtk_container_add (GTK_CONTAINER (window), button_box); 34 35 button = gtk_button_new_with_label ("Hello World"); 36 g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL); 37 g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_widget_destroy), window); 38 gtk_container_add (GTK_CONTAINER (button_box), button); 39 40 GdkPixbuf *icon; 41 icon = create_pixbuf("./icon.ico"); 42 gtk_window_set_icon(GTK_WINDOW(window), icon); 43 44 gtk_widget_show_all (window); 45 } 46 47 int main (int argc, char **argv) { 48 putenv("GTK_CSD=0"); 49 50 GtkApplication *app; 51 int status; 52 53 app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE); 54 g_signal_connect (app, "activate", G_CALLBACK (activate), NULL); 55 status = g_application_run (G_APPLICATION (app), argc, argv); 56 g_object_unref (app); 57 58 return status; 59 }