Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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 ( #1019112=note: print w/ replies, xml ) Need Help??


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

Can you prove it?

Nevermind

http://search.cpan.org/grep?cpanid=ROBERTMAY&release=Win32-GUI-1.06&string=Menu&i=1&n=1&C=0

http://cpansearch.perl.org/src/ROBERTMAY/Win32-GUI-1.06/GUI.pm

###################################################################### +######### # (@)PACKAGE:Win32::GUI::Menu # Create and manipulate menu resources # package Win32::GUI::Menu; @ISA = qw(Win32::GUI); ################################################################## +######### # (@)METHOD:new Win32::GUI::Menu(...) sub new { my $class = shift; my $self = {}; if($#_ > 0) { return Win32::GUI::MakeMenu(@_); } else { my $handle = Win32::GUI::CreateMenu(); if($handle) { $self->{-handle} = $handle; bless($self, $class); return $self; } else { return undef; } } }

So if what you get isn't an object, bless it :)

$handle = bless { -handle => $handle }, 'Win32::GUI::Menu';

Or stick with the functional interface (see Win32::GUI::Tutorial::Part1)

I'd just bless it though

Actually I'd switch to wxWidget


Comment on Re: How to get a window's menu as a Win32::GUI::Menu object?
Download Code
Re^2: How to get a window's menu as a Win32::GUI::Menu object?
by shadrack (Acolyte) on Feb 17, 2013 at 08:33 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)

        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

        Which is why I don't understand why it's relevant. How does it help my solve the problem?

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

        Fair enough:

        #!perl use Win32::GUI; &Main(); exit 0; 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, -text => 'Menu Test', -width => 300, -height => 200, -onTerminate => \&Main_Terminate, ); $WinMain->Show(); Win32::GUI::Dialog(); } sub Main_Terminate { -1; } sub Alpha_Select { 1; } sub Beta_Select { my($Window)=@_; my $menuhandle=$Window->GetMenu(); my $menu = bless { -handle => $menuhandle }, 'Win32::GUI::Menu'; $menu->{'Beta'}->Enabled(0); # Doesn't work. return 1; }
        You know, I could, or you could just read the link I posted :)

        You posted a link to the tutorial. As I explained, I've already read the tutorial. I read it AGAIN after you posted the link, and yet AGAIN just now. I've read it three times in the last hour and still -- I don't see anything that's relevant to the problem, so again, can you please point out specifically what it is in the tutorial that's going to help me solve my problem?

        Also, where are you getting your information from?

        http://perl-win32-gui.sourceforge.net/cgi-bin/docs.cgi

        http://www.mail-archive.com/perl-win32-gui-users@lists.sourceforge.net/msg00945.html

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2014-07-26 05:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls