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 <shadr...@rocketmail.com>
> To: "perl-win32-gui-users@lists.sourceforge.net" 
> <perl-win32-gui-users@lists.sourceforge.net>
> 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/perl-win32-gui-users@lists.sourceforge.net/msg00945.html).
>   
> Unfortunately, the current version of Win32::GUI doesn't appear to recognize 
> $Window->Menu
> 
> Thx,
> 
> - PF
> 

------------------------------------------------------------------------------
The Go Parallel Website, sponsored by Intel - in partnership with Geeknet, 
is your hub for all things parallel software development, from weekly thought 
leadership blogs to news, videos, case studies, tutorials, tech docs, 
whitepapers, evaluation guides, and opinion stories. Check out the most 
recent posts - join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
http://perl-win32-gui.sourceforge.net/

Reply via email to