Just creating a blank window is not enough, let's add a button to the window we created.
With hello,world! As an example.
First create a source file: The example2.c content is as follows.
#include <gtk/gtk.h>//the function that is called after the button is clicked for output Hello,worldStatic voidPrint_msg (Gtkwidget *button, gpointer data) {printf ("Hello, world!\n.");}Static voidActivate (Gtkapplication *app, gpointer data) {Gtkwidget*win; //Declare a buttonGtkwidget *button; //Declare a box container to hold the button, control the sizeGtkwidget *Button_box; Win=gtk_application_window_new (APP); Gtk_window_set_title (Gtk_window (Win),"Button Test"); Gtk_window_set_default_size (Gtk_window (Win), $, $); //Create a box container and set a horizontal placementButton_box = Gtk_button_box_new (gtk_orientation_horizontal);//Gtk_orientation_horizontal//include the box container into the windowGtk_container_add (Gtk_container (Win), Button_box); //Create a button with the label "My button"button = Gtk_button_new_with_label ("My Button"); //connect the signal so that the PRINT_MSG function is called when the button is clickedG_signal_connect (Button,"clicked", G_callback (print_msg), NULL);
//put the button in the box containerGtk_container_add (Gtk_container (button_box), button); //Show window and all its controlsGtk_widget_show_all (Win);}intMainintARGC,Char**argv) {gtkapplication*app; intApp_status; App= Gtk_application_new ("Org.gtk.exmple", 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;}
Compile and run the results as follows:
Linux from the beginning again gtk+-3.0 (ii)