緙栧啓涓涓寘鍚獹TK+嫻嬭瘯浠g爜鐨凜鏂囦歡錛屾坊鍔犲埌欏圭洰閲岄潰錛屽唴瀹瑰涓嬶細
#include <gtk/gtk.h>
static void destroy(GtkWidget*, gpointer);
static gboolean delete_event(GtkWidget*, GdkEvent*, gpointer);
int main(int argc, char *argv[]) {
GtkWidget *window, *label;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW (window), "Hello World!");
gtk_container_set_border_width(GTK_CONTAINER (window), 10);
gtk_widget_set_size_request(window, 200, 100);
/* Connect the main window to the destroy and delete-event signals. */
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL);
g_signal_connect(G_OBJECT(window), "delete_event",
G_CALLBACK(delete_event), NULL);
/* Create a new GtkLabel widget that is selectable. */
label = gtk_label_new("Hello World");
gtk_label_set_selectable(GTK_LABEL (label), TRUE);
/* Add the label as a child widget of the window. */
gtk_container_add(GTK_CONTAINER (window), label);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
/* Stop the GTK+ main loop function when the window is destroyed. */
static void destroy(GtkWidget *window, gpointer data) {
gtk_main_quit();
}
/* Return FALSE to destroy the widget. By returning TRUE, you can cancel
* a delete-event. This can be used to confirm quitting the application. */
static gboolean delete_event(GtkWidget *window, GdkEvent *event, gpointer data) {
return FALSE;
}
(浠ヤ笂浠g爜鏉ヨ嚜鍥句功 Foundation of GTK+ development)
鐒跺悗榪愯錛屾甯鎬細鏄懼紡濡備笅錛?br />