Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

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

by Anonymous Monk
on Feb 17, 2013 at 09:04 UTC ( #1019120=note: print w/ replies, xml ) Need Help??


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

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)


Comment on Re^3: How to get a window's menu as a Win32::GUI::Menu object?
Re^4: How to get a window's menu as a Win32::GUI::Menu object?
by shadrack (Acolyte) on Feb 17, 2013 at 09:51 UTC
    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

      Fair enough: CODE

      Employing Basic debugging checklist I get

      ( bless({ -handle => 28640341, Alpha => bless({ -id => 102, -menu => 41813267 }, "Win32::GUI::M +enuItem"), Beta => bless({ -id => 103, -menu => 41813267 }, "Win32::GUI::M +enuItem"), Program => bless({ -handle => 41813267 }, "Win32::GUI::MenuButton" +), }, "Win32::GUI::Menu"), bless({ # tied Win32::GUI::Window -accel => 0, -handle => 7734092, -name => "Main", -type => 0, }, "Win32::GUI::Window"), ) bless({ -handle => 13304919 }, "Win32::GUI::Menu")

      so what you want to do is skip GetMenu and either use global variables , or store $Menu inside $WinMain

      Like this

      #!/usr/bin/perl -- #!perl use Win32::GUI; use Data::Dump; Main( @ARGV ); 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(); $WinMain->{__special_Menu} = $Menu; dd $Menu, $WinMain; Win32::GUI::Dialog(); delete $WinMain->{__special_Menu}; # "DESTROY"/destructor/manual m +emory cycle break } 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'; dd $menu; #~ $menu->{'Beta'}->Enabled(0); # Doesn't work. $Window->{__special_Menu}->{'Beta'}->Enabled(0); return 1; }

      Useful regarding memory management, Tutorials: Variable Scoping in Perl: the basics, Coping with Scoping , Mini-Tutorial: Perl's Memory Management, Lexical scoping like a fox, Read this if you want to cut your development time in half!

      I'll be back with more:) maybe

        I don't know, but it certainly answers the question you asked , and I quote
        "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? "

        Yes, but not just any old object -- THE object the handle was associated with. Sorry, but I would have thought this was obvious given the context of the question. :-/

        I am actually using a global now, but I'm looking for a way around it since I'm also using threads which sometimes don't seem to play well with global Win32::GUI object variables.

        Anyway, thanks for the suggestions. Storing $Menu inside $WinMain is the solution I'm looking for. I tried something like this before (on a different Win32::GUI issue), but I couldn't make it work -- it's been a while, but IIRC the stored variable refused to "stick" to the object (it was undefined when I tried to access it later). Chalk it up to my lack of understanding of perl's object handling I guess.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2014-07-11 22:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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








    Results (235 votes), past polls