Niemiec, Greg wrote:
> Hello Everyone,
>
> Has anyone played with the MENU construct yet... or have
> any examples?
there is plenty of examples in the "samples" subdirectory
of the Win32-GUI distribution.
anyway, this is the Menu construct documentation (I hope
it makes sense, if anybody has hints/corrections please
let me know, I will include this in the documentation):
new Win32::GUI::Menu(
TEXT => NAME,
TEXT => NAME,
# ...
);
TEXT is the text that will appear on the menu item;
you can put a "&" in front of the letter you want
underlined on it (you can then access the corresponding
top-level menu with Alt and the letter, or the menu
item with the letter).
Example:
"&File" (you can open this menu with Alt-F)
" > &Load" (you can choose this option with L
while you are in the File menu)
There is a special text "-" that indicates a menu
separator.
To structure your menu, you can insert a ">" to
indicate a level down in the hierarchy; top-level
menus (items in the menu bar) have no ">", and then
you can create popup and submenus with one or more
">"s.
Example:
"&File"
" > &Load"
" > &Save"
" > E&xport"
" > > Plain &Text"
" > > &Other formats..."
" > -"
" > &Exit"
"&Edit"
" > Cu&t"
" > &Copy"
" > &Paste"
In the example, you have two top-level menus ("File" and
"Edit"); under "File", you have "Load", "Save", "Export",
a separator, and "Exit". The "Export" option opens another
submenu with "Plain Text" and "Other formats...".
Note that the whitespaces between ">"s and menu items are
optional, " > &Load" can be written as ">&Load" or even
" > &Load".
Now for the NAME parameters; they are, in the simplest
case, the names you will use to trigger events associated
to menu items, or to access menu items properties in your
code.
Example:
$Menu = new Win32::GUI::Menu(
"&File" => "File",
" > &Load" => "FileLoad",
);
In this example, when you select the "Load" menu item,
a "FileLoad_Click" event will be fired, so you'll have:
sub FileLoad_Click {
# got a menu click!
}
Furthermore, you can access the item itself as a hash
key in the $Menu object, eg.:
$Menu->{FileLoad}
For example, if you want to change the text for this
item to "Load File", you go like this:
$Menu->{FileLoad}->Change( -text => "&Load File" );
Note that the ">" is gone away, since it was only used
in constructing the menu structure.
In a less simple case, NAME can hold more information
than just the name; it can in fact be a hash reference
with MenuItem specific options. For example, if you want
your "Load" item to be initially disabled, you can use:
"> &Load" => { -name => "FileLoad", -enabled => 0 },
Note the hash reference (curly brackets) around options.
Finally, in the special case of a menu separator, the
NAME parameter can simply be 0 (zero), because it is
really not needed (but you have to put something in
there).
Let's complete our example menu:
$Menu = new Win32::GUI::Menu(
"&File" => "File",
" > &Load" => "FileLoad",
" > &Save" => "FileSave",
" > E&xport" => "FileExport",
" > > Plain &Text" => "FileExportText",
" > > &Other formats..."
=> "FileExportOther",
" > -" => 0,
" > &Exit" => "FileExit",
"&Edit" => "Edit",
" > Cu&t" => {
-name => "EditCut",
-enabled => 0,
},
" > &Copy" => {
-name => "EditCopy",
-enabled => 0,
},
" > &Paste" => "EditPaste",
);
phew! ;-)
cheers,
Aldo
__END__
$_=q,just perl,,s, , another ,,s,$, hacker,,print;