GtkWindow from wxWindow GetHandle Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
tt3
Earned a small fee
Earned a small fee
Posts: 10
Joined: Tue Jan 11, 2011 10:19 pm

GtkWindow from wxWindow GetHandle

Post by tt3 » Tue Jan 11, 2011 11:23 pm

I'm using ubuntu hardy with wxWidgets 2.8. I need to get XID from a window for image stream display, so I used the following:

wxWindow* window_;
...
GtkWidget* widget = window_->GetHandle();
XID xid = GDK_WINDOW_XWINDOW(widget->window);

This does not give any error, but no image gets shown. I tried using paint event to draw the images, and it worked. So I wonder, for the XID approach to work, is there some specific settings that I missed, or procedures to be taken for creating a window? And is wxWindow the right class?

The example codes I have (to use the XID) was in gtk, and it worked fine:

GtkWidget* drawing_area = gtk_drawing_area_new ();
...
XID xid = GDK_WINDOW_XWINDOW(drawing_area->window);

So I got another question that is there a way to get a GtkWidget pointer equivilant to the result of gtk_drawing_area_new(), out of either wxWindow or any other wxWidget class?

Thanks

upCASE
Site Admin
Site Admin
Posts: 3176
Joined: Mon Aug 30, 2004 6:55 am
Location: Germany, Cologne

Post by upCASE » Wed Jan 12, 2011 7:41 am

Hi!
I had the same problems when trying to tell VLC to use a wxWidgets control for video output.

Here's how I managed that for 2.8:

Code: Select all

GdkWindow* win = GTK_PIZZA(output->m_wxwindow)->bin_window;
vlc_media_player_set_xwindow (m_media_player_inst,GDK_WINDOW_XID(win));
For 2.9 I had to use a different way, as the internal window handling changed:

Code: Select all

GtkWidget* widget = output->GetHandle();
gtk_widget_realize( widget );   // Mandatory. Otherwise it segfaults.
Display* display = GDK_WINDOW_XDISPLAY( widget->window );
Window wid = GDK_WINDOW_XWINDOW( widget->window );   // Window is a typedef for XID, which is a typedef for unsigned int
vlc_media_player_set_xwindow (m_media_player_inst, wid);
In both cases "output" is the widget (in my case a panel) I use for displaying the video output.
I'm pretty sure that the 2.9 could be simplified, but I was tired of digging deeper into that, as this already took me some time to find out.

Hope this helps!
OS: OpenSuSE, Ubuntu, Win XP Pro
wx: svn
Compiler: gcc 4.5.1, VC 2008, eVC 4

"If it was hard to write it should be hard to read..." - the unknown coder
"Try not! Do. Or do not. There is no try." - Yoda

tt3
Earned a small fee
Earned a small fee
Posts: 10
Joined: Tue Jan 11, 2011 10:19 pm

Post by tt3 » Wed Jan 12, 2011 11:23 pm

Thanks very much. It worked.

Post Reply