Before we added a button to the window, let's make the button a little richer. and add a label to the window.
First create the example3,c source file.
#include <gtk/gtk.h>Static voidActivate (Gtkapplication *app, gpointer data);//load a picture from a fileGdkpixbuf *create_pixbuf (Const Char*image_name); intMainintARGC,Char**argv) {gtkapplication*app; intApp_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), argc, argv); G_object_unref (APP); returnApp_status;}Static voidActivate (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), $, $); Gtk_window_set_position (Gtk_window (window), gtk_win_pos_center); //Create icon control iconsicon = Create_pixbuf ("Icon.png"); //set icons for WindowsGtk_window_set_icon (Gtk_window (window), icon); //Create a button with an accelerator key, hold down ALT, and then press C, which is equivalent to clicking the buttonbutton = Gtk_button_new_with_mnemonic ("_close"); //set an informational cue bar for a buttonGtk_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); g_signal_connect_swapped (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 picture file, second parameter set error variable, no need to set to NULLPixbuf =gdk_pixbuf_new_from_file (Image_name, NULL); if(!pixbuf) {Perror ("gdk_pixbuf_new_from_file () \ n"); returnNULL; } returnpixbuf;}
Compile and run:
gcc example.c 'pkg-config --cflags--libs gtk+-3.0'. /a.out
Results:
Linux and go from the beginning gtk+-3.0 (iii)