#include <GUIConstantsEx.au3>
#include <ListBoxConstants.au3>
Opt('GUIOnEventMode', 1)
$hMain = GUICreate('Test', 600, 500)
$iLBox = GUICtrlCreateList('', 125, 120, 125, 250)
$iTestB = GUICtrlCreateButton('TEST', 320, 200, 70, 40)
For $i = 1 To 10
GUICtrlSendMsg($iLBox, $LB_INSERTSTRING, -1, 'String ' & $i)
Next
GUISetState()
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit', $hMain)
GUICtrlSetOnEvent($iTestB, '_Tester')
While Sleep(1000)
WEnd
Func _Tester()
Local $i_Ind, $t_Txt = DllStructCreate('wchar[4096]'), $p_Txt = DllStructGetPtr($t_Txt)
$i_Ind = GUICtrlSendMsg($iLBox, $LB_GETCURSEL, 0, 0)
If $i_Ind < 0 Then
$i_Ind = Random(0, GUICtrlSendMsg($iLBox, $LB_GETCOUNT, 0, 0) - 1, 1)
GUICtrlSendMsg($iLBox, $LB_SETCURSEL, $i_Ind, 0)
EndIf
GUICtrlSendMsg($iLBox, $LB_GETTEXT, $i_Ind, $p_Txt)
MsgBox(64, 'Info', 'Index: ' & $i_Ind & @LF & 'Text: ' & DllStructGetData($t_Txt, 1))
EndFunc ;==>_Tester
Func _Exit()
Exit
EndFunc ;==>_Exit