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

how to attach a pixmap to a GtkWindow as the background picture



I want to attach a pixmap to a GtkWindow as the background.
There is a function 'gdk_window_set_back_pixmap` , but this function
'gdk_window_set_back_pixmap` only supports GdkWindow.
My application is using GtkWindow which let me can add other widgets to
the window.
_GtkWidget struct has a parameter GdkWindow *window, I use
gtk_widget_realize(..) to set the window of the GtkWindow and then
called 'gdk_window_set_back_pixmap` function to set the background
pixmap. but it doesn't work! I wonder why?

If anybody can help me, please tell me ASAP!
thanks

The following is the source code (test example), it only include one
table and
one button:
I use gtk_window_new to create window1 and use gtk_widget_realize to set

window1->window, then I use gdk_window_set_back_pixmap to set the pixmap
as
the background. but when run the application, it does not show the
pixmap.  I
wonder what's wrong?

Need help!!
Thanks very very much!

#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <gtk/gtk.h>
#include "interface.h"

GtkWidget*
create_window1 ()
{
  GtkWidget *window1;
  GtkWidget *table1;
  GtkWidget *button1;
  GdkPixmap *pixmap;
  GdkBitmap *mask;
  GtkStyle *style;

  window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_object_set_data (GTK_OBJECT (window1), "window1", window1);
  gtk_widget_set_usize (window1, 640, 480);
  gtk_window_set_title (GTK_WINDOW (window1), "window1");
  //set windows->window, which is GdkWindow
  gtk_widget_realize(window1);

  //create table
  table1 = gtk_table_new (10, 10, FALSE);
  gtk_widget_ref (table1);
  gtk_object_set_data_full (GTK_OBJECT (window1), "table1", table1,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (table1);
  gtk_container_add (GTK_CONTAINER (window1), table1);

  //create button
  button1 = gtk_button_new_with_label ("button1");
  gtk_widget_ref (button1);
  gtk_object_set_data_full (GTK_OBJECT (window1), "button1", button1,
                            (GtkDestroyNotify) gtk_widget_unref);
  gtk_widget_show (button1);
  gtk_table_attach (GTK_TABLE (table1), button1, 4, 5, 8, 9,
                    (GtkAttachOptions) (0),
                    (GtkAttachOptions) (0), 0, 0);

  //create pixmap
  style=gtk_widget_get_style(window1);

pixmap=gdk_pixmap_create_from_xpm(window1->window,&mask,&style->bg[GTK_STATE_NORMAL],"./BACKGROUND.XPM");

  gdk_window_set_back_pixmap(window1->window,pixmap,0);

  gdk_window_show(window1->window);

   return window1;
}

int main (int argc, char *argv[])
{
 GtkWidget* window1;

 gtk_init(&argc,&argv);

 window1=create_window1 ();

 gtk_widget_show (window1);

 //start gtk+ main loop
 gtk_main ();
}






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