|
From: Paul F. <sha...@ro...> - 2013-02-18 22:39:33
|
Wow, don't everybody reply at once. :-|
For the record, I found a solution, or rather somebody at PerlMonks found it. Anyway, it works for me:
There doesn't appear to be any way to do this with the functions provided by Win32::GUI. But you can get around it by storing the menu object as an ad-hoc property of the window object. For example:
sub Main {
my $Menu = Win32::GUI::MakeMenu(
'&Program' => 'Program',
' > &Alpha' => { -name => 'Alpha', -onClick => \&Alpha_Select },
' > &Beta' => { -name => 'Beta', -onClick => \&Beta_Select },
);
my $WinMain = Win32::GUI::Window->new(
-name => 'Main',
-menu => $Menu,
...
);
$WinMain->{MyMenu} = $Menu;
...
}
sub Beta_Select {
my($Window)=@_;
$Window->{MyMenu}->{'Beta'}->Enabled(0);
...
}
- PF
----- Original Message -----
> From: Paul Floyd <sha...@ro...>
> To: "per...@li..." <per...@li...>
> Cc:
> Sent: Saturday, February 16, 2013 11:28 PM
> Subject: [perl-win32-gui-users] How do I get a window's Win32::GUI::Menu object?
>
>( sorry for the repeat -- accidentally hit send before giving it a subject)
>
> How do I get a window's Win32::GUI::Menu object?
>
> I have a
> function that has the main window handle in a local variable ($Window).
> I want to disable one of the items in this window's menu.
> Initially, I thought this would be easy, but:
>
> $Window->GetMenu();
>
> returns a menu HANDLE, not an object reference. This doesn't seem to help
> me -- unless there's a way to turn the handle into an object?
>
> $Window->{-menu}
>
> returns nothing.
>
> Ultimately what I'm trying to accomplish is something like:
> $Window->Menu->{'MyMenuItem'}->Enabled(0);
>
> Which used to work according to a VERY old message from this list
> (http://www.mail-archive.com/per...@li.../msg00945.html).
> Unfortunately, the current version of Win32::GUI doesn't appear to recognize
> $Window->Menu
>
> Thx,
>
> - PF
>
|