<?xml version="1.0" encoding="windows-1252"?>
<node id="18279" title="How do I use Win32::GUI::ListBox?" created="2000-06-15 13:55:03" updated="2005-08-11 06:59:26">
<type id="1857">
categorized question</type>
<author id="11732">
QandAEditors</author>
<data>
<field name="doctext">
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)&lt;br&gt;&lt;br&gt;

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&lt;br&gt;&lt;br&gt;

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 &lt;g&gt;&lt;br&gt;&lt;br&gt;

in the "theListBox" function at the bottom i need some help
if you know how to do this, please help&lt;br&gt;&lt;br&gt;

for the rest, i hope it helps the "newbies"&lt;br&gt;&lt;br&gt;

&lt;code&gt;
use Win32::GUI;


# i don't know what this line is for but i assume you need it &lt;g&gt;
($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 =&gt; "My Funky Class",
#	   -icon =&gt; $dbv_icon,
#);



my $DataMenu = new Win32::GUI::Menu(
	# pulldown heading, note the "&amp;" andpersand, 
	# in this context it is used to indicate 
	# which letter gets the little underliney bit

	"&amp;File" =&gt; "File",

  	# pulldown subheading
	"   &gt;  Open &amp;Headcount" =&gt; "Headcount",

	# pulldown subheading separator
	"   &gt;   -" =&gt; 0,
	"   &gt;   E&amp;xit" =&gt; "FileExit",

	# This is to re-enforce menu-building structure
	"&amp;Next" =&gt; "AnotherMenuHeading",
	"   &gt;   -" =&gt; 0,
);

# hopefully this is self explanitory

$DataWindow = new Win32::GUI::Window(
	-name   =&gt; "DataWindow",
	# orientation, where the window starts
	-top    =&gt; ($screen_width - $minwidth)/2,
	-left   =&gt; ($screen_height - $minheight)/2,
	# taken from the constants above ... these are the dimensions o
	-width  =&gt; $minwidth,
	-height =&gt; $minheight,

	-title  =&gt; 'Simple Win32::GUI Window ' .
		   "- by Alex Chesser (with some blatant CutandPaste from Jonathan) ",
	#put the menu (defined in "$DataMenu" above) onto the window
	-menu   =&gt; $DataMenu,

	# make a little icon (notes above)
	#-class  =&gt; $dbv_class,
);


# this is where we build and orient the 
# listbox, it's sortof like painting it 
# on the window

$theListBox = $DataWindow-&gt;AddListbox(
	-name     =&gt; "TheListBox",
	-text     =&gt; "&amp;The List Box",
	-top      =&gt; 30,
	-left     =&gt; 15,
	-height   =&gt; 120,
	-width    =&gt; 20,
	-multisel =&gt; 0,
);
$theListBox-&gt;InsertItem('0');
$theListBox-&gt;InsertItem('1');
$theListBox-&gt;InsertItem('2');
$theListBox-&gt;InsertItem('3');
$theListBox-&gt;InsertItem('4');
$theListBox-&gt;InsertItem('5');
$theListBox-&gt;InsertItem('6');
$theListBox-&gt;InsertItem('7');

# same as $theListBox but for a button
# i included this one to show you 
# something that works ;)

$Headcount = $DataWindow-&gt;AddButton(
	-name   =&gt; "Headcount",
	-text   =&gt; "Open &amp;Headcount",
	-top    =&gt; 15,
	-left   =&gt; $DataWindow-&gt;ScaleWidth -95,
	-width  =&gt; 90,
	-height =&gt; 25,
);

#  after the above "painting" stage, we display the window.
$DataWindow-&gt;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-&gt;SelectedItem();
	print ",$ListSelection\n";
}

# someone clicks File-&gt;exit
sub FileExit_Click {
   exit(0);
}

# someone clicks the 'X' window (haha ... not the X-window but the x on the window)
sub DataWindow_Terminate {
   exit(0);
}
&lt;/code&gt;
</field>
<field name="parent_node">
15433</field>
</data>
</node>
