Listboxes and Events

BlitzPlus Forums/BlitzPlus Programming/Listboxes and Events

em22(Posted 2008) [#1]
Hi everyone, I'm trying to capture event data from within a Listbox, but Blitzplus seems to be unable to send me the results of key presses and mouse clicks natively.

Basically I am writing a front end to WinUae that points to a folder of adf files, and displays all the games in a listbox. I want to be able to use the cursor keys to move up and down in the list box (as already works), but I also want the space key to run a certain command, maybe f1, f2 to run the emu with different confutations for example.

Also, I want to be able to detect a right click in the list box. Everything else I have tried works fine in other areas of the GUI, but the list box.

Can anyone help?


blackgecko(Posted 2008) [#2]
You must use <<SelectedGadgetItem()>> to find out which listbox entry is selected. <<EventData()>> doesn't work in listboxes.


In B+ V1.11 a right click in the listbox is not noted, in V1.45 it is noted like a left click. But no matter which version you use, a right click can't be detected.


em22(Posted 2009) [#3]
Yes, I've already got that far. I actually want to register input while in a list box, ie key presses mouse clicks etc. I know the OS already uses the inputs for movement within a listbox (like pressing "a" jumps to A in the list) Maybe I could extract the events with WinAPI. But I not too familiar.

I wish Mark would update this feature and fix it. It's the only thing that does not work as it should.

Plus how did you get to v1.45? I'm fully up to date but my IDE, linker and runtime all report 1.44.

I have even tried to use the BLESS sdk, which works to a degree, but then the listbox features seem a little broke there too.

Thanks!


blackgecko(Posted 2009) [#4]
To your problem with V1.45: If you installed the update for V1.45 you are really up to date. The information in the "About"-window is not right, but that's normal. Another user put this problem into a topic:
http://www.blitzbasic.com/Community/posts.php?topic=73218


BenjaminBlitz(Posted 2015) [#5]
Well this is a bit late, but it may help others understand how to achieve this.

Here is a working example...







;Create Timers
FreqTimer=CreateTimer(15)

;Variables
Global var1Sec#=1
Global Event
Global varOption$

;Create a Window
MainWindow=CreateWindow("My Window",0,0,300,ClientHeight(Desktop()),Desktop(),1)

;Create a ListBox
listbox=CreateListBox(10,50,275,200,MainWindow)
AddGadgetItem listbox,"Option1 - Red",0
AddGadgetItem listbox,"Option2 - White",0
AddGadgetItem listbox,"Option3 - Blue",0

;Create a Lable
label=CreateLabel("No Selection Made",10,250,275,30,MainWindow)



While Not KeyHit(1)

Event=WaitEvent()

;Window Close Event
If Event=$803 Then
Exit
EndIf

;Get Input from ListBox interaction
If Not SelectedGadgetItem(listbox)=-1 Then

;Print SelectedGadgetItem(listbox)

;Convert Selected Item
Select SelectedGadgetItem(listbox)
Case 0
varOption="Red"
Case 1
varOption="White"
Case 2
varOption="Blue"
Default
varOption="No Selection Made"
End Select

;Display the Selection
;Print varOption
SetGadgetText label,varOption

;Unselect listbox item
SelectGadgetItem listbox,-1

End If

Wend

End




Enjoy!