2

我正在编写一个 Gtk2 应用程序,其中需要将Mplayer视频播放到GtkDrawingArea. 据我所知,如果可以找到 XIDGtkDrawingArea并将其作为参数传递给 Mplayer,这是可能的。但是,我正在使用下面的代码片段。

long videoID;                 
GtkWidget *videoWindow = NULL;


/* need be done only once on Namb2Client startup */
InitEGM( &egm );    

/* Init GTK+ */
gtk_init( &argc, &argv );

/* Create new GtkBuilder object */
builder = gtk_builder_new();

/* Load UI from file. If error occurs, report it and quit application. */
if( !gtk_builder_add_from_file( builder, "layout.xml", &error ) )
{
    g_warning( "%s", error->message );
    g_free( error );
    return( 1 );
}

/* Get main window pointer from UI */
window = GTK_WIDGET( gtk_builder_get_object( builder, "window1" ) );
gtk_window_position(GTK_WINDOW(window), (GtkWindowPosition)GTK_WIN_POS_CENTER);


MainWnd = GTK_WIDGET( gtk_builder_get_object( builder, "MainWnd" ) );

// Setup area for Mplayer video
videoWindow = gtk_drawing_area_new ();
gtk_widget_set_size_request (videoWindow, 640, 180);
gtk_fixed_put((GtkFixed *)MainWnd, videoWindow, 414, 24 );
gtk_widget_show( videoWindow );    
videoID = gdk_x11_drawable_get_xid( videoWindow );
g_printf("XID = %ld\n", videoID);

当我运行应用程序时,我收到以下错误:

(egm:3872): Gdk-WARNING **: gdkdrawable-x11.c:952 drawable is not a pixmap or window
XID = 0

获取 a 的 XID 的正确方法是GtkDrawingArea什么?任何帮助将不胜感激。

4

1 回答 1

2

发现了问题。我需要确保打电话gtk_widget_realize()。如果不这样做,小部件就没有完全创建,也没有分配一个 X11 XID。

// Setup area for Mplayer video
videoWindow = gtk_drawing_area_new ();
gtk_widget_set_size_request (videoWindow, 640, 180);
gtk_fixed_put((GtkFixed *)MainWnd, videoWindow, 414, 24 );
gtk_widget_realize( videoWindow );
gtk_widget_show( videoWindow );    
videoID = GDK_WINDOW_XWINDOW (GTK_WIDGET (videoWindow)->window);
g_printf("XID = %ld\n", videoID);
于 2012-05-01T20:59:01.683 回答