-- from Ex06.exw by David Cuny
-- This opens a window with a populated list in it.
-- Wolf added onChange[] to show it's use.

include win32lib.ew

constant
    Win   = create( Window, "List +", 0, Default, Default, 160, 130, 0 ),
    List1 = create( List, "", Win, 10, 10, 120, 58, 0 ),    
--  ^^ create a list-box window.
    Label1 = create(RText, "", Win, 10, 75, 120, 20, 0)
--  ^^ create a right-justified text display window.

procedure onLoad_Win( integer self, integer event, sequence params )
    -- add these items to the listbox    
    addItem( List1, "one" )
    addItem( List1, "two" )
    addItem( List1, "three" )
    addItem( List1, "four" )
    addItem( List1, "five" )
    addItem( List1, "six" )
    addItem( List1, "seven" )
-- ** add another line here !!
	addItem( List1, "eight" )
end procedure

procedure show_it(integer here)
	-- show the selected list item in the text window.
--	integer here = getIndex( List1 )
	sequence this
	this=getItem(List1,here)
	setText(Label1, this)
end procedure

procedure onChange_List( integer self, integer event, sequence params )
-- get the latest index from the listbox, then show it.
	atom wwhere
	wwhere=getIndex( List1 )
	show_it( wwhere )
end procedure

setHandler( Win, w32HOpen, routine_id( "onLoad_Win" ) )
setHandler( List1, w32HChange, routine_id("onChange_List") )
-- ^^ this event handler is triggered whenever List1 changes state.

WinMain( Win,Normal )
