Ted's Blog

Happy coding

glade和libglade

CFLAGS = $(shell pkg-config --cflags gtk+-2.0 libglade-2.0)
LDFLAGS = $(shell pkg-config --libs gtk+-2.0 libglade-2.0)

main: main.o

.c.o:
    $(CC) -g $(CFLAGS) -c $< -o $@

clean:
    rm -f *.o main
这样就很容易产生可执行文件了.

下面是main.c的原文件内容
/***************************************************************************
 *       main.c
 *
 *  Wed Aug 17 12:42:58 2005
 *  Copyright  2005  YangH , GNOME-cn
 *  http://www.gnome-cn.org
 ****************************************************************************/




#include <stdio.h>

#include <gtk/gtk.h>
#include <glade/glade.h>

#define GLADE_FILE "./glade-custom-widget-demo.glade"

GtkWidget* custom_widget_create (gchar *widget_name, gchar *string1, gchar *string2,
                               gint int1, gint int2);

int main (int argc, char **argv)
{
    GtkWidget *window;
    GladeXML *xml;

    gtk_init (&argc, &argv);

    xml = glade_xml_new (GLADE_FILE, NULL, NULL);
    glade_xml_signal_autoconnect (xml);
   
    gtk_main ();

    return 0;
}

GtkWidget* custom_widget_create (gchar *widget_name, gchar *string1, gchar *string2,
                               gint int1, gint int2)
{
    GtkWidget *widget;
    GtkWidget *box, *button;

    box = gtk_vbox_new (FALSE, 4);
    button = gtk_button_new_with_label(g_strdup_printf ("Name: %s", widget_name));
    gtk_box_pack_start (GTK_BOX(box), button, FALSE, FALSE, 4);

    widget = gtk_label_new (g_strdup_printf ("string1: %s", string1));
    gtk_box_pack_start (GTK_BOX(box), widget, FALSE, FALSE, 4);
    widget = gtk_label_new (g_strdup_printf ("string2: %s", string2));
    gtk_box_pack_start (GTK_BOX(box), widget, FALSE, FALSE, 4);

    /* This very important */
    gtk_widget_show_all (box);
   
    return box;
}