Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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

( #18279=categorized question: print w/ replies, xml ) Need Help??
Contributed by Buckaroo Buddha on Jun 15, 2000 at 17:55 UTC
Q&A  > GUI Programming


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); }

Answer: How do I use Win32::GUI::ListBox?
contributed by Buckaroo Buddha

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 :)!

Please (register and) log in if you wish to add an answer

  • 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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (5)
    As of 2016-07-26 08:08 GMT
    Find Nodes?
      Voting Booth?
      What is your favorite alternate name for a (specific) keyboard key?

      Results (233 votes). Check out past polls.