/* Compile with: gcc -Wall -o backimage `pkg-config --cflags --libs gtk+-3.0` backimage.c */ #include <gtk/gtk.h> int main(int argc, char *argv[]) { GtkWidget *window; /*----- CSS ----------- */ GtkCssProvider *provider; GdkDisplay *display; GdkScreen *screen; /*-----------------------*/ gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); /* gtk_window_set_default_size (GTK_WINDOW(window), 500, 300); */ g_signal_connect (GTK_WIDGET(window), "destroy", G_CALLBACK (gtk_main_quit), NULL); /*------------- CSS --------------------------------------------------------------------------------------------------*/ provider = gtk_css_provider_new (); display = gdk_display_get_default (); screen = gdk_display_get_default_screen (display); gtk_style_context_add_provider_for_screen (screen, GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_USER); gtk_css_provider_load_from_data (GTK_CSS_PROVIDER (provider), " GtkWindow {\n" " background-image: url(‘abstract-blue-02.jpg‘);\n" "}\n", -1, NULL); g_object_unref (provider); /*----------------------------------------------------------------------------------------------------------------------*/ gtk_widget_show_all (window); gtk_main (); return(0); }
原文地址:http://blog.csdn.net/sjin_1314/article/details/42425625