Coincidentally, I've been working on a similar problem and was very interested to read this. My latest project involves using threads to perform lengthy tasks, but showing a progress bar with a 'Cancel' button on the main (or child) window. The problem is that the sharing of blessed variables is not yet supported in
threads::shared, so you have to share the handle and use the
Win32::GUI::Show($win) syntax. That's OK for one window, but it gets old and ugly when you want to access many controls on the window. Hence, I would also be interested to hear of a way to convert a handle into a Win32::GUI object. Are
there any other uses for this? Is it worth adding as a feature request?

I must admit, I've thought the same thing (and for almost the same reason) - which is why when I first replied I was talking about objects rather than static function calls.

From a technical perspective - and I admit I've only spent a couple of
minutes looking in to this- it should be possible to have a generic CreateFromHandle constructor that could be used to create most Win32::GUI objects (such as DC, Window ect). The first issue that would have to be resolved is ownership of the underlying windows handle, as when a Win32::GUI object goes out of scope the window handle is destroyed. A more significant issue is that some of the more complicated objects (such as window) have various structures associated with them when they were built via Win32::GUI - I suspect that many of these structures couldn't be filled via CreateFromHandle, meaning some functionality might me lost. For example:

my $win=Win32::GUI::Window::CreateFromHandle($handle);
$win->Show; #no problem
$win->Hide; #no problem
$win->SomeControl->Show(); #how would we know a control called 'SomeContol' exists?

I can think some work arounds for the above - especially if the window was created by Win32-GUI in another thread, which brings me to the issue of thread ownership of controls/windows - but the guitest guys know all about that:)

Cheers,

jez.



Reply via email to