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

全部博文(284)

文章存档

2012年(18)

2011年(33)

2010年(83)

2009年(147)

2008年(3)

分类: C/C++

2010-04-15 20:33:30

编译:

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


源码:

#include <stdio.h>
#include <stdlib.h>
#include "gtk/gtk.h"

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

int main( int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *button;
    GtkWidget *box1;
    GtkWidget *box2;
    GtkWidget *separator;
    GtkWidget *label;
    GtkWidget *quitbox;
    int which;
    
    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);
    gtk_container_set_border_width (GTK_CONTAINER (window), 10);
    
    box1 = gtk_vbox_new (FALSE, 0);
    
    //下面函数中第一个参数表示控制每个物件是否有同样的宽或高

    box2 = gtk_hbox_new (TRUE, 0);
    label = gtk_label_new ("first:");
     gtk_misc_set_alignment (GTK_MISC (label), 0, 0);
     gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0);
    gtk_widget_show (label);
    
    separator = gtk_hseparator_new ();
    gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, FALSE, 5);
    gtk_widget_show (separator);
    
    {
        button = gtk_button_new_with_label ("111111111");
        //expand = TRUE的话它们会填满box中所有额外的空间

        //fill=TRUE该物件会自行产生额外空间

         gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 10);
         gtk_widget_show (button);
        
         button = gtk_button_new_with_label ("2");
         gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 10);
         gtk_widget_show (button);
        
         button = gtk_button_new_with_label ("3");
         gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 10);
         gtk_widget_show (button);
    }
    
    gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0);
    gtk_widget_show (box2);

    quitbox = gtk_hbox_new (FALSE, 0);
    button = gtk_button_new_with_label ("Quit");
    
    g_signal_connect_swapped (G_OBJECT (button), "clicked",
             G_CALLBACK (gtk_main_quit),
             window);
    
    gtk_box_pack_start (GTK_BOX (quitbox), button, TRUE, FALSE, 0);
    gtk_box_pack_start (GTK_BOX (box1), quitbox, FALSE, FALSE, 0);
    gtk_container_add (GTK_CONTAINER (window), box1);

    gtk_widget_show (button);
    gtk_widget_show (quitbox);
    
    gtk_widget_show (box1);
    gtk_widget_show (window);
    gtk_main ();
    return 0;
}


阅读(561) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~