Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

How do I use Win32::GUI::ListBox?

by Buckaroo Buddha (Scribe)
on Jun 15, 2000 at 17:55 UTC ( [id://18279]=perlquestion: print w/replies, xml ) Need Help??

Buckaroo Buddha has asked for the wisdom of the Perl Monks concerning the following question:

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.

Replies are listed 'Best First'.
Re: How do I use Win32::GUI::ListBox?
by Buckaroo Buddha (Scribe) on Jun 15, 2000 at 21:25 UTC
    never one to shy away from answering my own question i've brought you all a version of a solution to the 'listbox problem'

    i have been working through the debug process on this problem and think i have an answer ...

    Change the subroutine TheListBox_Click to TheListBox_GotFocus:
    sub TheListBox_GotFocus { my $ListSelection = $theListBox->SelectedItem(); print ",$ListSelection\n"; }
    hope this helps :)!
Re: How do I use Win32::GUI::ListBox?
by Shendal (Hermit) on Jun 15, 2000 at 19:07 UTC
    I have been working on a GUI chatterbox client on NT. I started with Win32::GUI, but I think that some of the features I would like just weren't there (yet?). However, I did find the module easy to program. If you're interested, I've included my code here. BTW, this make use of zzamboni's PerlMonkChat.pm (thanks zzamboni!).

    The code has been moved to the Code Catacombs -- please check it out: Win32::GUI Chatterbox client

    Cheers,
    Shen

    Originally posted as a Categorized Answer.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-19 19:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found