in reply to Re^3: How to Resize a Window in M$ Windows?
in thread How to Resize a Window in M$ Windows?

My own experience has taught me not to try create a Win32::GUI object from a handle, as you might do something wrong, or there might be other things at work that you might miss (I think the module actually ties the hash object to allow some magic). Best just let the module look after all that.

I've been doing this for a while, and there really isn't anything that can go wrong. If you know different, I would appreciate an actual example over caution :)

  • Comment on Re^4: How to Resize a Window in M$ Windows?

Replies are listed 'Best First'.
Re^5: How to Resize a Window in M$ Windows?
by kejohm (Hermit) on Feb 11, 2011 at 04:42 UTC

    After looking at the Win32::GUI source, I found that the object constructor does tie the hash object before blessing it. You notice this when you dump the contents of a window object:

    $ perl -MWin32::GUI -MData::Dump=dump -e "dump Win32::GUI::Window->new +();" bless({ # tied Win32::GUI::Window -accel => 0, -handle => 460108, -name => "#3698ef4", -type => 0, }, "Win32::GUI::Window")

    Apparently, according to the source, it is needed to "get/set properties in a more fashionable way", whatever that means :)

    Even some of Win32::GUI's own methods only return handles, rather than objects. For example, the Win32::GUI::DC methods CreateDC(), and GetDC(), as well as methods that return some kind of resource, such as a menu, icon, image list, etc.

    I would say that, in most instances, you can get away with creating your own objects, but if your code doesn't run how it should, they could be the source of the problem.