Geoffrey Spear wrote:
Hi.

I've got a script that adds a MenuItem to my Window menu for each
MDIChild I create.  However, I can't figure out how to get the OnClick
event for each window to act on the correct window.

You don't need to do this yourself. Win32::GUI can be used to do it automatically. See the MDI.pl sample script, and look for the -windowmenu option of the AddMDIClient() method.

Regards,
Rob.

Here's a code snippet:
my $sid = $tray->{SID}; # ID to be used in window title
  my $twin = trayWindow($tray); # returns an MDI Child window

  $twin->Show();

  $menu->{"&Window"}->AddMenuItem(
                            -name => $sid,
                            -text => $sid,
                            -onClick =>sub 
{Win32::GUI::BringWindowToTop($twin); return 1;}
                           );

As it's written, if I click any of the added items in the menu, the
last window I created gets brought to the top.

I'm not sure why that doesn't work, but it's a bit difficult to tell without seeing more code, and I'm never sure I completely understand the behaviour of closures ...

Can anyone tell me how to get the anonymous subroutine refernce I'm
creating in the -onClick line to use the value of $twin it's got when
I create the subroutine, rather than the value at runtime?

Is there a way for an onClick event to get the name of the actual
menuItem that was clicked rather than just a reference to the Window
that contains the menu, which is fairly useless?

Sadly not at the moment. And not trivial to implement, as it's something that would be really useful. If I ever get enough time to visit the menu code, then I'll look at it in more detail (unless someone beats me to it?).

Regards,
Rob.
--
Robert May
Win32::GUI, a perl extension for native Win32 applications
http://perl-win32-gui.sourceforge.net/


Reply via email to