Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1119612
  • 博文数量: 284
  • 博客积分: 8223
  • 博客等级: 中将
  • 技术积分: 3188
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-01 13:26
文章分类

全部博文(284)

文章存档

2012年(18)

2011年(33)

2010年(83)

2009年(147)

2008年(3)

分类: C/C++

2010-04-14 11:54:24

#include<gtk/gtk.h>

void callback(GtkWidget *widget, gpointer data){
  g_print("Hello again -%s was pressed\n", (gchar*) data);
}

gint delete_event(GtkWidget *widget, GdkEvent *event, gpointer data){
  gtk_main_quit();
  return TRUE;
}

void destory(GtkWidget *widget, gpointer data){
    gtk_main_quit();
}

int main(int argc,char *argv[]){
  GtkWidget *window;
  GtkWidget *button;
  GtkWidget *box1;

  gtk_init(&argc,&argv);
  window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_window_set_title(GTK_WINDOW(window), "Hello Buttons\n");
  //窗口关闭按钮

  g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(delete_event), NULL);
  //exit按钮

  g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destory), NULL);
  gtk_container_set_border_width(GTK_CONTAINER(window), 10);
  
  box1 = gtk_hbox_new(FALSE, 0);
  gtk_container_add(GTK_CONTAINER(window), box1);
  button = gtk_button_new_with_label("Button1");
  g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(callback), "button1");
  gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
  gtk_widget_show(button);

  button = gtk_button_new_with_label("Button2");
  g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(callback), "button2");
  gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
  gtk_widget_show(button);
  
  button = gtk_button_new_with_label(" exit ");
  g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(callback), "exit");
  g_signal_connect_swapped(G_OBJECT(button), "clicked",G_CALLBACK(gtk_widget_destroy), window);
  gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
  gtk_widget_show(button);
  
  gtk_widget_show(box1);
  gtk_widget_show(window);
  gtk_main();
  return 0;
}

 

cc ss.c -o ss `pkg-config --cflags --libs gtk+-2.0`


阅读(1393) | 评论(0) | 转发(0) |
0

上一篇:gtk-窗口消息与按钮

下一篇:视窗box布局

给主人留下些什么吧!~~