当前位置: 技术问答>linux和unix
Gtk下(linux)如何设置窗体的背景图片?
来源: 互联网 发布时间:2015-07-27
本文导语: gtk_winodw_new创建的窗体,如何设置一个gif的图片做为其背景图呢?谢谢!回答都有分!能解答的可再给分,万分感谢! | #include #include GdkPixmap *load_pixmap(GtkWidget *widget,gchar *filename) { Gdk...
gtk_winodw_new创建的窗体,如何设置一个gif的图片做为其背景图呢?谢谢!回答都有分!能解答的可再给分,万分感谢!
|
#include
#include
GdkPixmap *load_pixmap(GtkWidget *widget,gchar *filename)
{
GdkPixbuf *pixbuf=NULL;
GdkPixmap *pixmap=NULL;
pixbuf=gdk_pixbuf_new_from_file(filename,NULL);
if(!widget->window)printf("NULLn");
pixmap=gdk_pixmap_new(widget->window,gdk_pixbuf_get_width(pixbuf),
gdk_pixbuf_get_height(pixbuf),-1);
gdk_pixbuf_render_to_drawable(pixbuf,pixmap,
widget->style->fg_gc[GTK_STATE_NORMAL],
0,0,0,0,
gdk_pixbuf_get_width(pixbuf),
gdk_pixbuf_get_height(pixbuf),
GDK_RGB_DITHER_NORMAL,0,0);
g_object_unref(pixbuf);
return pixmap;
}
gboolean set_widget_bg(gchar *filename,GtkWidget *widget)
{
GdkPixmap *bg;
bg=load_pixmap(widget,filename);
gdk_window_set_back_pixmap(widget->window,bg,FALSE);
gdk_window_clear(widget->window);
return TRUE;
}
int main(int argc,char* argv[])
{
GtkWidget *window,*fix ;
gtk_init(&argc,&argv) ;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL) ;
gtk_signal_connect(GTK_OBJECT(window),"destroy",GTK_SIGNAL_FUNC(gtk_main_quit),NULL) ;
fix = gtk_fixed_new() ;
gtk_container_add(GTK_CONTAINER(window),fix) ;
set_widget_bg("wcan.png",fix) ;
gtk_widget_show(fix) ;
gtk_widget_show_all(window) ;
gtk_main() ;
return 0 ;
}
#include
GdkPixmap *load_pixmap(GtkWidget *widget,gchar *filename)
{
GdkPixbuf *pixbuf=NULL;
GdkPixmap *pixmap=NULL;
pixbuf=gdk_pixbuf_new_from_file(filename,NULL);
if(!widget->window)printf("NULLn");
pixmap=gdk_pixmap_new(widget->window,gdk_pixbuf_get_width(pixbuf),
gdk_pixbuf_get_height(pixbuf),-1);
gdk_pixbuf_render_to_drawable(pixbuf,pixmap,
widget->style->fg_gc[GTK_STATE_NORMAL],
0,0,0,0,
gdk_pixbuf_get_width(pixbuf),
gdk_pixbuf_get_height(pixbuf),
GDK_RGB_DITHER_NORMAL,0,0);
g_object_unref(pixbuf);
return pixmap;
}
gboolean set_widget_bg(gchar *filename,GtkWidget *widget)
{
GdkPixmap *bg;
bg=load_pixmap(widget,filename);
gdk_window_set_back_pixmap(widget->window,bg,FALSE);
gdk_window_clear(widget->window);
return TRUE;
}
int main(int argc,char* argv[])
{
GtkWidget *window,*fix ;
gtk_init(&argc,&argv) ;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL) ;
gtk_signal_connect(GTK_OBJECT(window),"destroy",GTK_SIGNAL_FUNC(gtk_main_quit),NULL) ;
fix = gtk_fixed_new() ;
gtk_container_add(GTK_CONTAINER(window),fix) ;
set_widget_bg("wcan.png",fix) ;
gtk_widget_show(fix) ;
gtk_widget_show_all(window) ;
gtk_main() ;
return 0 ;
}
|
试试这个(部分代码)
GtkWidget *window;
GtkWidget *image;
GtkWidget *frame;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
image = gtk_image_new_from_file("*.gif");
frame = gtk_frame_new(NULL);
gtk_container_add (GTK_OBJECT(frame), image);
gtk_container_add (GTK_OBJECT(window), frame);
gtk_widget_show_all(window);
GtkWidget *window;
GtkWidget *image;
GtkWidget *frame;
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
image = gtk_image_new_from_file("*.gif");
frame = gtk_frame_new(NULL);
gtk_container_add (GTK_OBJECT(frame), image);
gtk_container_add (GTK_OBJECT(window), frame);
gtk_widget_show_all(window);
|
通知斑竹
叫他帮你解决~~
叫他帮你解决~~
|
UP
|
up