Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

How to get a window's menu as a Win32::GUI::Menu object?

by shadrack (Acolyte)
on Feb 17, 2013 at 03:44 UTC ( #1019097=perlquestion: print w/ replies, xml ) Need Help??
shadrack has asked for the wisdom of the Perl Monks concerning the following question:

How do I get a window's Win32::GUI::Menu object given the window object (let's say it's in the variable $Window)?

$Window->GetMenu();
returns a menu HANDLE, not an object reference. This seems to be more or less useless -- 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);

Google indicates this actually worked at one time, but apparently Win32::GUI has changed enough since then that the current version doesn't allow that.

Comment on How to get a window's menu as a Win32::GUI::Menu object?
Re: How to get a window's menu as a Win32::GUI::Menu object?
by Anonymous Monk on Feb 17, 2013 at 06:57 UTC
      Perhaps I've misunderstood you, but it appears blessing the handle just gives me a new (empty) menu. This does me no good as far as I can see. I'm trying to disable an item in an EXISTING menu -- the one attached to the main window.
      sub Main { my $Menu Win32::GUI::MakeMenu( '&Program' => 'Program', ' > &Settings' => { -name => 'Settings', -onClick => \&GU +I_Settings }, ' > &About' => { -name => 'About', -onClick => \&About +_Click }, ' > &Update' => { -name => 'Update', -onClick => \&Upda +te_Now }, ' > E&xit' => { -name => 'Exit', -onClick => \&Main_T +erminate } ); my $WinMain = Win32::GUI::Window->new( -name => 'Main', -menu => $Menu, ... ); ... } sub Update_Now { my($Window)=@_; # Disable the 'Update' menu item }
      As far as the functional interface goes, can you be more specific? I've read the tutorial several times. If there's something in there that helps me solve my problem, I'm not making the connection. Would you be so kind as to point it out?

        Perhaps I've misunderstood you, but it appears blessing the handle just gives me a new (empty) menu.

        I don't think so, blessing a hash doesn't create a handle (windows does that), it just gives you an object you can call methods on

        OTOH, the code you have posted includes no bless anywhere :)

        As far as the functional interface goes, can you be more specific?

        You know, I could, or you could just read the link I posted :)

        If you want anything more specific than that, you're going to have to post code that compiles and runs -- I'm not really interested in writing complete examples from scratch for non-portable-unmaintained-toolkits , its not fun for me :)

        Also, where are you getting your information from?

        See Win32/OLE related tutorials/examples/resources , they discuss many win32 things, how the MFC/win32-GUI system works (its all handles underneath, a handle is just a number)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1019097]
Approved by bulk88
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (12)
As of 2014-07-14 10:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (257 votes), past polls