# GtkDialog with GdkWindow as parent

**URL:** <https://www.ruby-forum.com/t/gtkdialog-with-gdkwindow-as-parent/85350>\
**Category:** Ruby\
**Created:** [February 12, 2007, 10:16pm UTC](https://www.ruby-forum.com/t/gtkdialog-with-gdkwindow-as-parent/85350 "2007-02-12T22:16:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmanruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@cmanruby](https://www.ruby-forum.com/u/cmanruby)\
**Post date:** [February 12, 2007, 10:16pm UTC](https://www.ruby-forum.com/t/gtkdialog-with-gdkwindow-as-parent/85350/1 "2007-02-12T22:16:16Z")

</div>

I am trying to create a Gtk::MessageDialog with a win32 window as its  
parent (the reason comes in the end). Now, it is possible to make a  
Gdk::Window wrapper using

require ‘gtk2’

win = Gdk::Window.foreign\_new ARGV[0].to\_i

But I cannot create a Gtk::MessageDialog with the Gdk::Window as  
parent

Gtk::MessageDialog.new(win,  
Gtk::MessageDialog::MODAL,  
Gtk::MessageDialog::INFO,  
Gtk::MessageDialog::BUTTONS\_OK,  
“foreign\_test”)

gives me the warning

GLib-GObject-WARNING \*\*:invalid cast from `GdkWindow' to`GtkWindow’

which is fair enough and the failed assertion

Gtk-CRITICAL \*\*:gtk\_message\_dialog\_new: assertion `parent == NULL ||  
GTK\_IS\_WINDOW (parent)’ failed

So: is there a way that I can create a Gtk::MessageDialog or other Gtk  
window with a Gdk window as parent?

For the curious minds: what I am trying to do is to make a ruby  
screensaver wrapper for win32. It consists of a .c executable that  
functions as a windows screensaver and invokes a ruby script that  
shall be the actual screensaver. When the windows “display properties”  
app wants to call the configuration dialog, it calls the executable  
with its own window handle as argument. This of cause works for  
windows apps, but shouldn’t it be possible to make this work with Gtk?

---

<div class="post-metadata">

**Author:** ![cmanruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@cmanruby](https://www.ruby-forum.com/u/cmanruby)\
**Post date:** [February 13, 2007, 1:59pm UTC](https://www.ruby-forum.com/t/gtkdialog-with-gdkwindow-as-parent/85350/2 "2007-02-13T13:59:55Z")

</div>

Hi,

On Tue, 13 Feb 2007 06:15:09 +0900  
“Christian M.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Gtk::MessageDialog.new(win,  
> Gtk::MessageDialog::MODAL,  
> Gtk::MessageDialog::INFO,  
> Gtk::MessageDialog::BUTTONS\_OK,  
> “foreign\_test”)
> 
> gives me the warning
> 
> GLib-GObject-WARNING \*\*:invalid cast from `GdkWindow' to `GtkWindow’
> 
> which is fair enough and the failed assertion

The error message means “Use Gtk::Window instead of Gdk::Window”.  
You need to use Gtk::Window as the parent.

---

<div class="post-metadata">

**Author:** ![cmanruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@cmanruby](https://www.ruby-forum.com/u/cmanruby)\
**Post date:** [February 13, 2007, 8:05pm UTC](https://www.ruby-forum.com/t/gtkdialog-with-gdkwindow-as-parent/85350/3 "2007-02-13T20:05:41Z")

</div>

On 13 Feb., 13:59, Masao M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > require ‘gtk2’  
> > “foreign\_test”)
> 
> > gives me the warning
> 
> > GLib-GObject-WARNING \*\*:invalid cast from `GdkWindow' to `GtkWindow’
> 
> > which is fair enough and the failed assertion
> 
> The error message means “Use Gtk::Window instead of Gdk::Window”.  
> You need to use Gtk::Window as the parent.

Thanks, Masao.

But is it then possible to create a Gtk::Window which is modal to the  
foreign Gdk::Window? Then I could use the Gtk::Window as a dialog…
