howto set background for GtkWidget

/**
* gcc -g -o gtk-setbg gtk-setbg.c `pkg-config gtk+-2.0 --cflags --libs gthread-2.0`
*/

#include <gtk/gtk.h>

int main( int   argc,
          char *argv[] )
{
    gtk_init (&argc, &argv);

    GtkWidget *dialog = gtk_dialog_new_with_buttons ("My dialog",
                                                 NULL,
                                                 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
                                                 GTK_STOCK_OK,
                                                 GTK_RESPONSE_ACCEPT,
                                                 GTK_STOCK_CANCEL,
                                                 GTK_RESPONSE_REJECT,
                                                 NULL);
    GdkPixmap *gdk_pixmap;
    GdkPixbuf *gdk_pixbuf =  gdk_pixbuf_new_from_file("background.png", NULL);  
    gdk_pixbuf_render_pixmap_and_mask (gdk_pixbuf, &gdk_pixmap,NULL, 0);
    GtkStyle *style = gtk_style_copy(dialog->style);
    style->bg_pixmap[GTK_STATE_NORMAL] = gdk_pixmap;
    gtk_widget_set_style (dialog, style);
    gtk_widget_show_all (dialog);

    gtk_main ();

    return 0;
}
 

 

你可能感兴趣的:(C++,c,gcc,C#)