Re: Why "GtkWidget->window" is "NULL" when "gtk_window_new()"



Thanks very much. But I have Another question:
I want to draw line on my own initiative, don't use "expose-event" and callback function.
Like the following code, but the code can't do what I want.
Please tell me how to do this?


Code:
+-------------------------------------------------------------------------------------
|	int main(int argc, char *argv[])
|	{
|		GtkWidget *w;
|
|		gtk_init(&argc, &argv);
|
|		w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|		g_signal_connect(GTK_OBJECT(w), "destroy", G_CALLBACK(gtk_main_quit), NULL);
|
|		gtk_widget_realize(w);
|		gdk_draw_line(w->window, w->style->fg_gc[GTK_WIDGET_STATE(w)],
|				0, 0, 120, 120);
|
|		gtk_widget_show_all(w);
|		gtk_main();
|		return 0; 
|	}
+-------------------------------------------------------------------------------------


On 8/11/08, Emmanuele Bassi <ebassi gmail com> wrote:
On Mon, 2008-08-11 at 17:45 +0800, Wu Yin wrote:
> Code:
> +----------------------------------------------------------
> | GtkWidget *w;
> |
> | w = gtk_window_new(GTK_WINDOW_TOPLEVEL);
> +----------------------------------------------------------
> Why the "w->window" is "NULL"?

the GdkWindow is created after a widget is realized (except for
NO_WINDOW widgets).

> The GdkDrawable is NULL ,how can I draw things on it?

use the "realize" signal: connect a callback to that signal and you're
guaranteed that widget->window will be available.

also, read the documentation:

http://library.gnome.org/devel/gtk/stable/GtkWidget.html#gtk-widget-realize

ciao,
Emmanuele.

--
Emmanuele Bassi,
W: http://www.emmanuelebassi.net
B: http://log.emmanuelebassi.net

_______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list



--
----------------------------------------------
┏━━━━━━━━━━━━━━━━━━━━━━━━┓
┃菩提本无树,明镜亦非台。本来无一物,何处惹尘埃。┃
┗━━━━━━━━━━━━━━━━━━━━━━━━┛

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