hwnd on win32

View: New views
5 Messages — Rating Filter:   Alert me  

hwnd on win32

by T.J. Ferraro :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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


I call it as:

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

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?

Thanks.
T.J.


_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: hwnd on win32

by T.J. Ferraro :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

After messing around a bit I realized it was actually giving me back the
hwnd, just in decimal form. A simple sprintf("%x", $hwnd) was able to
return to me the actual hex handle :)

T.J.

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
>
>
> I call it as:
>
> my $hwnd = Gtk2::Gdk::Drawable::gdk_win32_drawable_get_handle($drawable);
>
> 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?
>
> Thanks.
> T.J.
>
>


_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: hwnd on win32

by Torsten Schoenfeld :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: hwnd on win32

by T.J. Ferraro :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Torsten Schoenfeld wrote:

> 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 tried the following in a separate file GdkWin32.xs and instructed
Makefile.PL to add this file to the xs list if the platform was win32.
It compiles, but neither get_handle or gdk_win32_drawable_get_handle
appear as a Gtk2::Gdk::Drawable method...

#include "gtk2perl.h"
#include <gdk/gdkwin32.h>

MODULE = Gtk2::Gdk::Win32    PACKAGE = Gtk2::Gdk::Drawable    PREFIX =
gdk_win32_drawable_

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



>> 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();
>
>  
I applied your suggestion to my hack and put the following into
GdkDrawable.xs and now I can call the method get_handle on any drawable
and it works like a charm, thanks :)

MODULE = Gtk2::Gdk::Drawable    PACKAGE = Gtk2::Gdk::Drawable    PREFIX
= gdk_win32_drawable_

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

>> 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.
>
>  

I think you missed the follow up email I sent later. It actually turns
out it was in fact returning the value; the handle was being returned as
a base10 integer instead of base16. After getting that I just had to
sprintf("%x", $hwnd) and now I have what I need. I've been trying to get
this working as a separate xs file for about an hour to no avail. Since
I've got it working exactly as I wanted it to in the Drawable xs
file...I'm going to have to put off finishing that until next week when
I have more time. Thanks for the help =)

T.J.

_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Re: hwnd on win32

by Torsten Schoenfeld :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

T.J. Ferraro wrote:

> I tried the following in a separate file GdkWin32.xs and instructed
> Makefile.PL to add this file to the xs list if the platform was win32.
> It compiles, but neither get_handle or gdk_win32_drawable_get_handle
> appear as a Gtk2::Gdk::Drawable method...
>
> #include "gtk2perl.h"
> #include <gdk/gdkwin32.h>
>
> MODULE = Gtk2::Gdk::Win32    PACKAGE = Gtk2::Gdk::Drawable    PREFIX =
> gdk_win32_drawable_
>
> ## HGDIOBJ       gdk_win32_drawable_get_handle (GdkDrawable *drawable)
> gpointer
> gdk_win32_drawable_get_handle (drawable)
>    GdkDrawable *drawable

That looks alright and should work.  Can you show us the complete patch?

--
Bye,
-Torsten
_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@...
http://mail.gnome.org/mailman/listinfo/gtk-perl-list