GTK+2.0 之 hello world

类别:编程语言 点击:0 评论:0 推荐:
/* env:     gtk2.0 */
/*  gcc helloworld.c -o helloworld `pkg-config --cflags --libs gtk+-2.0`  */

#include <gtk/gtk.h>

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

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

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

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);
  g_signal_connect (G_OBJECT (window), "delete_event",
            G_CALLBACK (quit), NULL);

  button = gtk_button_new_with_label ("OK");

  g_signal_connect (G_OBJECT (button), "clicked",
            G_CALLBACK (ok), NULL);

  label = gtk_label_new ("Hello, world!");

  box = gtk_vbox_new (FALSE, 10);

  gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX (box), button, TRUE, FALSE, 0);

  gtk_widget_show (label);
  gtk_widget_show (button);
  gtk_widget_show (box);

  gtk_container_add (GTK_CONTAINER (window), box);

  gtk_widget_show (window);

  gtk_main ();

  return 0;
}

本文地址:http://com.8s8s.com/it/it22957.htm