problem while executing



/*
Hello gtk friends,
While executing a program packbox.c from my book,
the program has compiled properly,
but on executing I get this message repeatedly, which i suppose means that there is some problem with
my button=statements or some assignments.
the error message follows. beneath the error message is the types source code for packbox.c.
Can anyone help me please?
Thanks in advance.

------------------Error Message---------------------------------------
Error message while executing packbox.c
Gtk--Warning**:Invalid cast from'(unknown)' to 'GtkBox'
Gtk-Critical **:file gtkbox.c:line 330(gtk_box_pack_start):assertion 'GTK_IS_BOX(box)' failed.

---------------Sourcecode of packbox.c----------------------------------------------*/

#include<gtk/gtk.h>

GtkWidget *PackNewButton (GtkWidget *box,char *szlabel)
{
GtkWidget *button;
button=gtk_button_new_with_label(szlabel);
gtk_box_pack_start(GTK_BOX(box),button,FALSE,FALSE,0);
gtk_widget_show(button);
return(button);
}

gint destroyapp(GtkWidget *widget, gpointer gdata)
{
g_print("Quitting...\n");
gtk_main_quit();
return(FALSE);
}

int main(int argc, char *argv[])
{
GList *cbitems=NULL;

GtkWidget *hwindow;
GtkWidget *vwindow;
GtkWidget *button;
GtkWidget *box;

gtk_init(&argc,&argv);

vwindow=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(vwindow),"vertical box packing");
gtk_signal_connect(GTK_OBJECT(vwindow),"delete_event",GTK_SIGNAL_FUNC(destroyapp),NULL);
gtk_container_border_width(GTK_CONTAINER(vwindow),50);

gtk_vbox_new(FALSE,0);
button = PackNewButton(box,"Button1");
button = PackNewButton(box,"Button2");
button = PackNewButton(box,"Button3");
button = PackNewButton(box,"Button4");
button = PackNewButton(box,"Button5");

gtk_container_add(GTK_CONTAINER(vwindow),box);
gtk_widget_show(box);

gtk_widget_show(vwindow);

hwindow=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(hwindow),"horizontal box packing");
gtk_signal_connect(GTK_OBJECT(hwindow),"delete_event",GTK_SIGNAL_FUNC(destroyapp),NULL);
gtk_container_border_width(GTK_CONTAINER(hwindow),50);

gtk_hbox_new(FALSE,0);
button = PackNewButton(box,"Button1");
button = PackNewButton(box,"Button2");
button = PackNewButton(box,"Button3");
button = PackNewButton(box,"Button4");
button = PackNewButton(box,"Button5");

gtk_container_add(GTK_CONTAINER(hwindow),box);
gtk_widget_show(box);

gtk_widget_show(hwindow);
gtk_main();
return 0;
}






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]