GTK Widget事件信号回调解析是本文要介绍的内容,主要是来了解并学习GTK Widget,具体内容的学习来看本文详解。本文内容不多,主要是以代码里实现GTK Widget事件的处理。
- #include<gtk/gtk.h>
- void hello(GtkWidget *widget,gpointer data)
- {
- g_print("Hello Ubuntu!/n");
- }
- gint delete_event(GtkWidget *widget,GdkEvent *event,gpointer data)
- {
- g_print ("delete event occurred/n");
- gtk_main_quit();
- return(TRUE);
- }
- void destroy(GtkWidget *widget,gpointer data)
- {
- gtk_main_quit();
- }
- int main( int argc, char *argv[] )
- {
- GtkWidget *hbox;
- GtkWidget *window;
- GtkWidget *button;
- GtkWidget *buttonclose;
- gtk_init (&argc, &argv);
- window=gtk_window_new (GTK_WINDOW_TOPLEVEL);
- gtk_signal_connect (GTK_OBJECT(window),"delete_event",GTK_SIGNAL_FUNC(delete_event),NULL);
- gtk_signal_connect (GTK_OBJECT (window), "destroy",GTK_SIGNAL_FUNC (destroy), NULL);
- gtk_container_set_border_width (GTK_CONTAINER (window), 10);
- button = gtk_button_new_with_label ("Hello Ubuntu!11111111111111111111111111111111111");
- buttonclose=gtk_button_new_with_label("close");
- gtk_signal_connect (GTK_OBJECT (button), "clicked",GTK_SIGNAL_FUNC (hello), NULL);
- gtk_signal_connect_object (GTK_OBJECT (buttonclose), "clicked",GTK_SIGNAL_FUNC (gtk_widget_destroy),GTK_OBJECT (window));
- // gtk_container_add (GTK_CONTAINER (window), button);
- hbox=gtk_hbox_new (TRUE,5);
- gtk_box_pack_start(GTK_BOX(hbox),button,TRUE,FALSE,5);
- gtk_box_pack_start(GTK_BOX(hbox),buttonclose,TRUE,FALSE,5);
- gtk_container_add (GTK_CONTAINER(window),hbox);
- /* gtk_widget_show(buttonclose);
- gtk_widget_show (button);
- gtk_widget_show (hbox);
- gtk_widget_show (window); /*显示一个窗口*/
- gtk_widget_show_all(window);
- gtk_main(); /*进入主循环*/
- return(0);
- }
小结:GTK Widget事件信号回调解析的内容介绍完了,希望通过GTK Widget应用内容的学习能对你有所帮助!