Hey everyone, I'm fairly new to perl and experimenting with the Win32::GUI module. This is probably very easy but I can't get it to work. I'm trying to make an 'about' messagebox (providing info about the program version) appear when clicking on a menu item of a window. This is my code so far: First making the menu
use strict; use Win32::GUI(); my $Menu_id=1; my $Menu = new Win32::GUI::Menu(); my $MenuButton1 = $Menu->AddMenuButton( -text => "Menu", -id => $Menu_id++, ); my $MenuButton1_Quit = $MenuButton1->AddMenuItem( -text => "Quit", -id => $Menu_id++, -onClick => sub{print"program closed\n"; return -1;}, ); my $MenuButton1_About = $MenuButton1->AddMenuItem( -text => "About", -id => $Menu_id++, -onClick => $MessageBox_About->DoModal(), );
Then making the first window and include the menu
my $Main = new Win32::GUI::Window( -name => "MainWindow", -title => "Main Window", -pos => [ 100, 100 ], -size => [ 300, 200 ], -menu => $Menu, ); $Main->AddLabel( -name => "Label1", -text => "Welcome", -pos => [12,10], );
Then the messagebox showing the about info. Since there is no actual MessageBox() I just made a window with a label and a close button
my $MessageBox_About = new Win32::GUI::Window( -name => "AboutWindow", -title => "About this program", -pos =>[ 150, 150 ], -size => [150,150], -parent => $Main, ); $MessageBox_About->AddLabel( -name => "MsgBox_Label", -text => "Blabla", -pos => [20,20], ); $MessageBox_About->AddButton( -name => "MsgBox_Button", -text => "Ok", -pos => [50,40], ); sub MsgBox_Button_Click {return -1;} #closes the messagebox
The problem here of course is that $MessageBox doesn't exist yet when it's called at the MenuButton1 onClick event. The messagebox has the main window as parent and DoModal is used to prevent interaction in the main window while the about window is still visible. I tried an event handler sub
sub MenuButton1_About_Click{$MessageBox_About->DoModal(); return 0;}
But also doesn't work.. How to get this to work?

In reply to win32::GUI help [solved] by thomaster

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.