Win32Lib: Call for EXAMPLE programs
- Posted by Dan B Moyer <DANMOYER at PRODIGY.NET> Sep 03, 2000
- 418 views
Hi all, I'm working on a little thing relating to Win32Lib which might be of some help to newbies (& perennial newbies like myself), and it could benefit from some additional EXAMPLE programs illustrating how to do basic things with Win32Lib. Contributions of examples would be gratefully accepted and acknowledged. Here's what I mean: I asked a question about using right-clicks to select items in a listbox, and Al Getz sent me a sample program illustrating his solution. I modified it superficially, & it's below. It's the kind of thing others could find useful. But there's a lot of other example programs that like this that could help make using Win32Lib easier for newbies. That's what I'm asking for. TIA Dan --<code begins> -- Rclick: allows right clicking on an item in a list box to select & use it -- by Al Getz 9/2/00 ----------------------------------------------------------------------- include Win32Lib.ew without warning constant Desktop=0 ------------------------------------------------------------- -- creates controls: constant Window1= create(Window,"Allows RIGHT click to select item in listbox",Desktop,10,10,580,460,0) constant ListBox2=create(List,"2",Window1,40,20,260,200,0) -- label to show info from selected item in listbox: global constant DataLabel = create( CText, "", Window1, 0, 0, 40, 30, 0 ) ---------------------------------------------------------------- --fills listbox with demo items: for j=1 to 30 do addItem(ListBox2,"entry"&sprintf("%d",j)) end for ------------------------------------------------------- --defines constants if not already defined in Win32Lib.ew: -- ADD THIS TO YOUR PROGRAM (unless it gets added to Win32Lib) constant LB_GETITEMHEIGHT=#01A1, LB_GETTOPINDEX=#018E -- LB_SETCURSEL=#0186 ---------------------------------------------------- --puts an onMouse event in your program code: procedure onMouse_ListBox2(integer event, integer x, integer y, integer shift) -- ADD THESE VARIABLES TO YOUR PROGRAM in your onMouse event: atom index,bool,height,topindex,indexoffset sequence itemtext -- (insert YOUR routine's VARIABLES here:) if event=RIGHT_DOWN then -- note: can use "RightDown", also -- start of "housekeeping" to allow right click to work: height=sendMessage(ListBox2,LB_GETITEMHEIGHT,0,0) topindex=sendMessage(ListBox2,LB_GETTOPINDEX,0,0) indexoffset=floor(y/height) index=indexoffset+topindex bool=sendMessage(ListBox2,LB_SETCURSEL,index,0) index +=1 -- NOTE: USE "INDEX" TO REFERENCE TO ITEM SELECTED BY RIGHT CLICK -- end of right click housekeeping itemtext=getItem(ListBox2,index) -- shows item selected in list: -- (REMOVE or remark this in your program) setText(DataLabel,itemtext ) --put YOUR code to process the event here: -- end if end procedure onMouse[ListBox2]=routine_id("onMouse_ListBox2") ----------------------------------------------------------------- ------------------------------------------------------------------- ------------------------------------------------------------------- --may have to modify this last line for your version of Win32Lib: WinMain(Window1,Normal)