我正在尝试让我的GtkWindow在Windows后端透明,但程序失败了。我使用gtk + 3.6.1似乎gdk_window_set_opacity()函数不起作用,那么还有另一种解决方案吗?这是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include "gtk/gtk.h"
int main( int argc, char *argv[] )
{
gboolean user_func( GtkWidget *wid,
cairo_t *cr,
gpointer user_data );
gtk_init( &argc, &argv );
GtkWidget *win = gtk_window_new( GTK_WINDOW_TOPLEVEL );
gtk_window_set_title( GTK_WINDOW( win ), "Translucent window");
g_signal_connect( G_OBJECT( win ), "draw", G_CALLBACK( user_func ), NULL );
gtk_widget_show( win );
gtk_main();
return 0;
}
gboolean user_func( GtkWidget *wid,
cairo_t *cr,
gpointer user_data )
{
GdkWindow *window = gtk_widget_get_window( wid );
printf("bbbb\n"); // for debuging purpose
gdk_window_set_opacity( window, 0.5 );
printf("bonjour\n"); // for debuging purpose
cairo_set_source_rgba( cr, 0.0, 0.0, 1.0, 0.5 );
cairo_paint( cr );
GTK_WIDGET_GET_CLASS( wid )->draw( wid, cr );
return TRUE;
}
最好的问候。