Linux and then go from scratch GTK +-3.0 (3), gtk-3.0
Previously, we added a button for the window. Next, we will enrich the button. And add values to the window.
First, create the source file example3 and c.
# Include <gtk/gtk. h> static void activate (GtkApplication * app, gpointer data); // load an image GdkPixbuf * create_pixbuf (const char * image_name) from the file; int main (int argc, char ** argv) {GtkApplication * app; int app_status; app = gtk_application_new ("org. rain. gtk ", G_APPLICATION_FLAGS_NONE); g_signal_connect (app," activate ", G_CALLBACK (activate), NULL); app_status = g_application_run (G_APPLICATION (app), ar Gc, argv); g_object_unref (app); return app_status;} static void activate (GtkApplication * app, gpointer data) {GtkWidget * window; GdkPixbuf * icon; GtkWidget * button; gtkWidget * button_box; window = gtk_application_window_new (app); gtk_window_set_title (GTK_WINDOW (window), "icon test"); gtk_window_set_default_size (GTK_WINDOW (window), 200,200 ); gtk_window_set_position (GTK_WINDOW (window), GTK_WIN _ POS_CENTER); // create the icon control icon = create_pixbuf ("icon.png"); // set the window icon gtk_window_set_icon (GTK_WINDOW (window), icon ); // create a button with the acceleration key, hold down Alt and press C, which is equivalent to clicking the button = gtk_button_new_with_mnemonic ("_ Close "); // set a message prompt for the button: gtk_widget_set_tooltip_text (button, "Click button to quit. "); button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL); gtk_container_add (GTK_CONTAINER (button_box), button ); Gtk_container_add (GTK_CONTAINER (window), button_box); trim (button, "clicked", G_CALLBACK (gtk_widget_destroy), window); g_object_unref (icon); gtk_widget_show_all (window );} gdkPixbuf * create_pixbuf (const char * image_name) {GdkPixbuf * pixbuf; // load the image file. If the second parameter sets an error variable, set it to NULL pixbuf = gdk_buf_new_from_file (image_name, NULL); if (! Pixbuf) {perror ("gdk_pixbuf_new_from_file () \ n"); return NULL ;}return pixbuf ;}
Compile and run:
gcc example.c `pkg-config --cflags --libs gtk+-3.0`./a.out
Result: