Beginner question about drawing and GC



I wrote a very simple program, which should draw a rectangle on the left part of the main window ( main window contains a hbox with 2 columns)

===================================
code start
----------------------------------------
#include<gtk/gtk.h>
gint main(gint argc,gchar * argv[])
{
        GtkWidget * main;
        GtkWidget * hbox;
        GtkWidget * button;
        GtkWidget * draw;
        GdkDrawable * drawable;

        gtk_init(&argc,&argv);

        main = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_default_size(GTK_WINDOW(main),500,400);
        gtk_window_set_title(GTK_WINDOW(main),"New Window");
        gtk_signal_connect(GTK_OBJECT(main),"destroy",GTK_SIGNAL_FUNC(gtk_main_quit),NULL);

        gtk_widget_show(main);

        hbox = gtk_hbox_new(FALSE,10);
        gtk_container_add(GTK_CONTAINER(main),hbox);
        gtk_widget_show(hbox);

        draw = gtk_drawing_area_new();
        gtk_widget_set_usize(draw,300,300);
        gtk_box_pack_start(GTK_BOX(hbox),draw,TRUE,TRUE,5);
        gtk_widget_show(draw);
        drawable = draw->window;
        g_assert(drawable != NULL);
        
gdk_draw_rectangle(drawable,draw->style->black_gc,TRUE,100,100,(draw->allocation.width)/2,(draw->allocation.height)/2);


        button = gtk_button_new_with_label("Click Me");
        gtk_box_pack_end(GTK_BOX(hbox),button,FALSE,FALSE,0);

        gtk_widget_show_all(main);

        gtk_main();
        return 0;
}
-----------------------------------------------------
Code end
==================================

It runs ok but no content on the left cell. Then I comment the line
gtk_widget_show(main);
drawable will be NULL and an assert will given in runtime.

I am a newbee to GTK programming, anyone can help me to figure out the error?

Thanks!

_________________________________________________________________
Download games, logos, wallpapers and lots more at MSN Mobile! http://www.msn.com.sg/mobile/




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