here is a (modified) program that i've been working on
the original code comes from a gentleman named Jonathan
(the rest is left out to protect anonimity)
it's a pretty simple proggie and dosen't really do anything
but it runs (if you've installed win32::GUI). it's a reasonable "hello world" level example of how to make
a window and how to put buttons and stuff on it
i've added some comments ... i've also admitted
where i don't know what's going on ... if you do, changing the
comments to make them more useful would really be just GREAT <g>
in the "theListBox" function at the bottom i need some help
if you know how to do this, please help
for the rest, i hope it helps the "newbies"
use Win32::GUI;
# i don't know what this line is for but i assume you need it <g>
($DOShwnd, $DOShinstance) = GUI::GetPerlWindow();
# these lines close the dos window that pops up after executing the
# program from windows ... for testing, i'd leave them commented out
# click on the "headcount" button to see why
#
#GUI::CloseWindow($DOShwnd);
#GUI::Hide($DOShwnd);
# these are also important (i geuss) but i don't know why
my $screen_width = Win32::GUI::GetSystemMetrics(0);
my $screen_height = Win32::GUI::GetSystemMetrics(1);
# set the constants used for the dimensions of your box
my $minwidth = 350;
my $minheight = 200;
# if you have an icon handy when you run this
# section that icon becomes the fancy picture your
# program uses (you also got to un-comment the
# appropriate line under $DataWindow
#
# my $dbv_icon = new Win32::GUI::Icon("My.ico");
#
# my $dbv_class = new Win32::GUI::Class(
# -name => "My Funky Class",
# -icon => $dbv_icon,
#);
my $DataMenu = new Win32::GUI::Menu(
# pulldown heading, note the "&" andpersand,
# in this context it is used to indicate
# which letter gets the little underliney bit
"&File" => "File",
# pulldown subheading
" > Open &Headcount" => "Headcount",
# pulldown subheading separator
" > -" => 0,
" > E&xit" => "FileExit",
# This is to re-enforce menu-building structure
"&Next" => "AnotherMenuHeading",
" > -" => 0,
);
# hopefully this is self explanitory
$DataWindow = new Win32::GUI::Window(
-name => "DataWindow",
# orientation, where the window starts
-top => ($screen_width - $minwidth)/2,
-left => ($screen_height - $minheight)/2,
# taken from the constants above ... these are the dimensions o
-width => $minwidth,
-height => $minheight,
-title => 'Simple Win32::GUI Window ' .
"- by Alex Chesser (with some blatant CutandPaste from Jona
+than) ",
#put the menu (defined in "$DataMenu" above) onto the window
-menu => $DataMenu,
# make a little icon (notes above)
#-class => $dbv_class,
);
# this is where we build and orient the
# listbox, it's sortof like painting it
# on the window
$theListBox = $DataWindow->AddListbox(
-name => "TheListBox",
-text => "&The List Box",
-top => 30,
-left => 15,
-height => 120,
-width => 20,
-multisel => 0,
);
$theListBox->InsertItem('0');
$theListBox->InsertItem('1');
$theListBox->InsertItem('2');
$theListBox->InsertItem('3');
$theListBox->InsertItem('4');
$theListBox->InsertItem('5');
$theListBox->InsertItem('6');
$theListBox->InsertItem('7');
# same as $theListBox but for a button
# i included this one to show you
# something that works ;)
$Headcount = $DataWindow->AddButton(
-name => "Headcount",
-text => "Open &Headcount",
-top => 15,
-left => $DataWindow->ScaleWidth -95,
-width => 90,
-height => 25,
);
# after the above "painting" stage, we display the window.
$DataWindow->Show();
# then we tell it to enter a "mainloop", essentially
# sit there and and wait for inputs
# (for fun, comment it out and see what happens to the program)
Win32::GUI::Dialog();
# if the button named "Headcount" gets a "_Click", run this sub
sub Headcount_Click {
my $headcount_filename = Win32::GUI::GetOpenFileName();
print "$headcount_filename,$ListSelection\n";
}
# this is the bit that i'd like some help with
# i'd like to set
#
sub TheListBox_Click {
my $ListSelection = $theListBox->SelectedItem();
print ",$ListSelection\n";
}
# someone clicks File->exit
sub FileExit_Click {
exit(0);
}
# someone clicks the 'X' window (haha ... not the X-window but the x o
+n the window)
sub DataWindow_Terminate {
exit(0);
}
Originally posted as a Categorized Question.