The wxWindow::GetHandle() function returns HWND on Windows and GtkWidget on linux. I need to get X11 Window Handle, which isn't the widget itself. How can I get the handle from that widget? I need C++ code as it's the main language of wxWidgets.
Asked
Active
Viewed 7,474 times
1 Answers
18
Something like:
GtkWidget *widget = ...;
Window w = gdk_x11_drawable_get_xid(gtk_widget_get_window(widget));
It is C because Gtk+ is a C API, but it is also C++, so there should be no problem.
And don't forget to #include <gdk/gdkx.h>
!

rodrigo
- 94,151
- 12
- 143
- 190
-
Yea, I should have mentioned C too as gtk is in C and c++ is backwards compatible. What exactly is the "Window" type? – user1873947 Feb 09 '13 at 13:10
-
3`Window` is the type of a native XWindows window. It is defined as `typedef XID Window;`, and XID is itself an integral type that identifies most X resources (see `/usr/include/X11/X.h`). – rodrigo Feb 09 '13 at 13:12
-
Thank you. If I include wxwidgets and gdk/gdkx.h, will this type be known for the compiler? – user1873947 Feb 09 '13 at 13:14
-
Yes, `
` already includes any X11 header it needs . Other issue is whether you have to include any Gtk header, such as ` – rodrigo Feb 09 '13 at 13:16`. -
`gdk_x11_drawable_get_xid` is for gdk2, is there a solution for gdk3? – Noitidart Apr 10 '16 at 18:13
-
4@Noitidart In Gtk3 there is the equivalent `gdk_x11_window_get_xid()`. – rodrigo Apr 10 '16 at 18:40
-
Thanks @rodrigo that was it! :) – Noitidart Apr 11 '16 at 01:37