int main()
{
printf("hello Fedora!\n");
return 0;
}
#include
void hello(gtkwidget *widget,gpointer data)
{
g_print("hello Fedora!\n");
}
gint delete_event(gtkwidget *widget,gdkevent *event,gpointer data)
{
g_print ("delete event occurred\n"); return(true);
}
void destroy(gtkwidget *widget,gpointer data)
{ gtk_main_quit(); }
int main( int argc, char *argv[] ) {
gtkwidget *window;
gtkwidget *button;
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 Fedora!");
gtk_signal_connect (GTK_OBJECT (button), "clicked",GTK_SIGNAL_FUNC (hello), NULL);
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",GTK_SIGNAL_FUNC
(gtk_widget_destroy),GTK_OBJECT (window));
gtk_container_add (GTK_CONTAINER (window), button);
gtk_widget_show (button);
gtk_widget_show (window); /*显示一个窗口*/
gtk_main(); /*进入主循环*/
return(0);
}
{
printf("hello Fedora!\n");
return 0;
}
#include
void hello(gtkwidget *widget,gpointer data)
{
g_print("hello Fedora!\n");
}
gint delete_event(gtkwidget *widget,gdkevent *event,gpointer data)
{
g_print ("delete event occurred\n"); return(true);
}
void destroy(gtkwidget *widget,gpointer data)
{ gtk_main_quit(); }
int main( int argc, char *argv[] ) {
gtkwidget *window;
gtkwidget *button;
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 Fedora!");
gtk_signal_connect (GTK_OBJECT (button), "clicked",GTK_SIGNAL_FUNC (hello), NULL);
gtk_signal_connect_object (GTK_OBJECT (button), "clicked",GTK_SIGNAL_FUNC
(gtk_widget_destroy),GTK_OBJECT (window));
gtk_container_add (GTK_CONTAINER (window), button);
gtk_widget_show (button);
gtk_widget_show (window); /*显示一个窗口*/
gtk_main(); /*进入主循环*/
return(0);
}
用下面命令编译运行:
$ gcc gtkhello.c -o gtktest `pkg-config --cflags --libs gtk+-2.0`
$ ./gtktest
没有评论:
发表评论