How do I get the XWindow ID of my wxGTK wxWindow?
Code: Select all
//m_ctrl is the wxWindow (pretty sure this will work for wxFrame as well)
#ifdef __WXGTK__
# include "wx/gtk/win_gtk.h" //for <gdk/gdkx.h>/GDK_WINDOW_XWINDOW
#endif
GdkWindow *window = GTK_PIZZA(m_ctrl->m_wxwindow)->bin_window;
//This line contains the real Xid
GDK_WINDOW_XWINDOW( window )
The problem is that in order to get a valid xid your window needs to be
realized first, and if its not then you need to connect to the realize
event and handle it there.
Code: Select all
if(!GTK_WIDGET_REALIZED(m_ctrl->m_wxwindow))
{
//Not realized yet - set to connect at realization time
g_signal_connect (m_ctrl->m_wxwindow,
"realize",
G_CALLBACK (gtk_window_realize_callback),
this);
}
Where gtk_window_realize_callback is something like
Code: Select all
extern "C" {
static gint gtk_window_realize_callback(GtkWidget* theWidget,
MyClass* myc)
{
GdkWindow *window = GTK_PIZZA(theWidget)->bin_window;
//Now we have a good xid for sure
GDK_WINDOW_XWINDOW( window )
return 0;
}
}
(well you can use the same one you get early but if you use it before the window is realized the X server quits your program for you with an annoying error message informing you that you probably have a bug).
Edit by DavidHart: For an update, including wx2.9, see
this post