如果背景图片为透明背景的png,则可以实现非规则窗口。
详细看以下的两种方法:
#include
int main(int argc, char *argv[])
{
GtkWidget *window = NULL;
GdkPixbuf *pixbuf = NULL;
GdkPixmap *pixmap = NULL;
GdkBitmap *bitmap = NULL;
GtkWidget *fixed = NULL;
gtk_init(&argc,&argv);
/* Create the window */
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window),"ZQButton Demo");
gtk_widget_set_events(window, GDK_SCROLL_MASK);
gtk_widget_set_app_paintable(window,TRUE);
gtk_widget_realize (window);
//gtk_window_fullscreen(GTK_WINDOW(window));
gtk_widget_set_size_request(window, 800, 600);
g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
pixbuf = gdk_pixbuf_new_from_file ("./test.png",NULL);
gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, &bitmap, 128);
gtk_widget_shape_combine_mask(window, bitmap, 0, 0);
#if 0
GtkStyle *style = gtk_style_copy(window->style);
if(style->bg_pixmap[GTK_STATE_NORMAL])
g_object_unref(style->bg_pixmap[GTK_STATE_NORMAL]);
style->bg_pixmap[GTK_STATE_NORMAL] = g_object_ref(pixmap);
gtk_widget_set_style(window, style);
#else
fixed = gtk_fixed_new();
gtk_container_add (GTK_CONTAINER(window), fixed);
pixbuf = gdk_pixbuf_new_from_file ("./test.png",NULL);
pixmap = gdk_pixmap_new (fixed->window, gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf), -1);
gdk_pixbuf_render_to_drawable(pixbuf, pixmap,
fixed->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);
gdk_window_set_back_pixmap (fixed->window, pixmap, FALSE);
gtk_widget_show(fixed);
#endif
gtk_widget_show(window);
gtk_main();
return FALSE;
}
阅读(3946) | 评论(0) | 转发(0) |