#include <gtk/gtk.h>
void on_btn_clicked (GtkWidget *widget,gpointer data)
{ g_print(“Hello World!\n”); }
void on_delete (GtkWidget *widget,GdkEvent *event,gpointer data)
{ g_print(“Window Closed.\n”);
gtk_main_quit();
}
int main (int argc, char * argv[ ]){
GtkWidget *window;
GtkWidget *button;
gtk_set_locale();//设置gtk本地信息
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);
g_signal_connect(G_OBJECT(window),“delete_event”,G_CALLBACK(on_delete) 关联窗口关闭事件
button=gtk_button_new_with_label(“Hello World”);
g_signal_connect(G_OBJECT(button),“clicked”,G_CALLBACK(on_btn_clicked)
gtk_container_add(GTK_CONTAINER(window),button);
gtk_widget_show_all(window); //显示窗口
gtk_main(); //启动消息循环
return 0;}