Re: hwnd on win32



T.J. Ferraro wrote:
Trying to get the hwnd of a Gtk2::Gdk::Drawable on win32. After pouring 
through source I noticed nothing was being exported for this in 
gtk2-perl. I'm not really an XS expert (yet...) so I threw together a 
quick hack to try to get this working for me.

I modified GdkDrawable.xs by adding...

#include <gdk/gdkwin32.h>
And the following:

## HGDIOBJ       gdk_win32_drawable_get_handle (GdkDrawable *drawable)
gpointer
gdk_win32_drawable_get_handle (drawable)
    GdkDrawable *drawable

This would make more sense in a separate XS file GdkWin32.xs that only
gets compiled on the relevant platforms -- just like GdkX11.xs.  If you
want your changes going in, I think this is the way to go.

I call it as:

my $hwnd = Gtk2::Gdk::Drawable::gdk_win32_drawable_get_handle($drawable);

If you put the XSUB in its own MODULE ... PACKAGE ... PREFIX section,
you can turn that into

  my $hwnd = $drawable->get_handle();

Or maybe better yet

  my $hwnd = $drawable->get_win32_handle();

Works (a little ugly), but as you can imagine, it's not handing me back 
an hwnd, but rather numbers like: 1310846, 1245310, 983164.
Are these actual gpointers or am I getting garbage? Any way to 
dereference if it is actually returning a gpointer?

As you found out yourself, you get back a numeric representation of the
pointer.  You won't be able to do much with this pointer in pure Perl,
though.  There would need to be another CPAN module that provides XS
wrappers for whatever function you want to pass this handle to.

-- 
Bye,
-Torsten



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]