The following program example is a modified version of Ex06.exw which is included with the Win32lib program package. I have included it here because it illustrates the use of one additional function.
... and it takes us further into another 'control' window, the List , first used in lesson 5.
When I was working to create the tutorial
'engine' for these lessons I wanted some way for a simple text window
to display the included demo programs outside of the listbox window.
I tried all kinds of ways to do this, and eventually came up with
an onKeyPress() event handling routine which checked to see which of
the arrow keys I had pressed. This then updated a pointer to the
list, read the corresponding program example, and then updated the
text window.
No matter what I tried though, I could not get the
mouse activity to do the same.
EUREKA !
Sometimes it really helps to sit back and
read the documentation even if most of it seems incomprehensible.
There it was.. the onChange[] event handler, almost documented in the
'depths' of win32lib.ew itself. So I tried it.. hey !.. just what I
was looking for.
So here's a demonstration of onChange[].
--
lists1.exw
-- from Ex06.exw by David Cuny
-- This opens a window with a populated list in it.
-- Wolf(y).. ;-) added setHandler( List1, w32HChange, routine_id("onChange_List") ) 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 listbox window.
Label1 = create(RText, "", Win, 10, 70, 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" )
end procedure
procedure show_it(integer here)
-- show the selected list item in the text window.
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" ) )
-- ^^ the routine that runs when the window first opens.
setHandler( List1, w32HChange, routine_id("onChange_List") )
-- ^^ this event handler is triggered whenever List1 changes state.
WinMain( Win,Normal )
-- end of lists1.exw... and this is what it looks like.
The text window 'magically' follows
whatever is selected in the listbox.
...and yes, there is another
line to be added here, to display the first setIndex()'d line after
'filling' the list with AddItem() ...
..end of lesson.