GTK+ FAQ
<<< Previous | Development with GTK+: general questions | Next >>>

# How do I create a pixmap without having my window being realized/shown?

Functions such as `gdk_pixmap_create_from_xpm()` require a valid window as a parameter. During the initialisation phase of an application, a valid window may not be available without showing a window, which may be inappropriate. In order to avoid this, a function such as `gdk_pixmap_colormap_create_from_xpm` can be used, as in:

      char *pixfile = "foo.xpm";
      GtkWidget *top, *box, *pixw;
      GdkPixmap *pixmap, *pixmap_mask;

      top = gtk_window_new (GKT_WINDOW_TOPLEVEL);
      box = gtk_hbox_new (FALSE, 4);
      gtk_conainer_add (GTK_CONTAINER(top), box);

      pixmap = gdk_pixmap_colormap_create_from_xpm (
                   NULL, gtk_widget_get_colormap(top),
                   &pixmap_mask, NULL, pixfile);
      pixw = gtk_pixmap_new (pixmap, pixmap_mask);
      g_object_unref (pixmap);
      g_object_unref (pixmap_mask);

<<< Previous | Home | Next >>>
How do I render pixels (image data) to the screen? | Up | How do I do drag-and-drop?