Zu Punkt 1.
Du musst natürlich auch angeben welche Position aus der Liste ausgelesen werden soll. "$iCode", ist glaube ich in dem Code für etwas anderes verantwortlich nicht für die Position.
Ich habe dir mal eine Funktion zur Erkennung des angewählten Beitrags eingebaut.
Spoiler anzeigen
#include <GUIListBox.au3>
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
$Debug_LB = False ; Prüft den Klassennamen (ClassName), der an die ListBox-Funktion übergeben wird. Setze dies versuchsweise auf True und verwende dann ein Handle zu einem anderen Control, um die Funktionsweise zu verstehen.
[/autoit] [autoit][/autoit] [autoit]Global $hListBox
[/autoit] [autoit][/autoit] [autoit]_Main()
[/autoit] [autoit][/autoit] [autoit]Func _Main()
Local $hGUI
; Erstellt eine GUI
$hGUI = GUICreate("(UDF) ListBox: Erzeugen", 400, 296)
$hListBox = _GUICtrlListBox_Create($hGUI, "String bei Erzeugung", 2, 2, 396, 296, $LBS_SORT)
GUISetState()
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
[/autoit] [autoit][/autoit] [autoit]; Fügt Dateien hinzu
_GUICtrlListBox_BeginUpdate($hListBox)
_GUICtrlListBox_ResetContent($hListBox)
_GUICtrlListBox_InitStorage($hListBox, 100, 4096)
_GUICtrlListBox_AddString($hListBox, "Musterfrau D1")
_GUICtrlListBox_AddString($hListBox, "Mustermann D2")
_GUICtrlListBox_AddString($hListBox, "Musterkind D3")
_GUICtrlListBox_AddString($hListBox, "Mustermum D4")
_GUICtrlListBox_AddString($hListBox, "Musterdad D5")
_GUICtrlListBox_AddString($hListBox, "Musterfrau DK1")
_GUICtrlListBox_AddString($hListBox, "Mustermann DK2")
_GUICtrlListBox_AddString($hListBox, "Musterkind DK3")
_GUICtrlListBox_AddString($hListBox, "Mustermum DK4")
_GUICtrlListBox_AddString($hListBox, "Musterdad DK5")
_GUICtrlListBox_AddString($hListBox, "Musterfrau DKD 1")
_GUICtrlListBox_AddString($hListBox, "Mustermann DKD 2")
_GUICtrlListBox_AddString($hListBox, "Musterkind DKD 4")
_GUICtrlListBox_AddString($hListBox, "Mustermum DKD4")
_GUICtrlListBox_AddString($hListBox, "Musterdad DKD5")
_GUICtrlListBox_AddString($hListBox, "Musterfrau PD1")
_GUICtrlListBox_AddString($hListBox, "Mustermann PD2")
_GUICtrlListBox_AddString($hListBox, "Musterkind PD3")
_GUICtrlListBox_AddString($hListBox, "Mustermum PD4")
_GUICtrlListBox_AddString($hListBox, "Musterdad PD5")
_GUICtrlListBox_AddString($hListBox, "Musterfrau PDK1")
_GUICtrlListBox_AddString($hListBox, "Mustermann PDK2")
_GUICtrlListBox_AddString($hListBox, "Musterkind PDK3")
_GUICtrlListBox_AddString($hListBox, "Mustermum PDK4")
_GUICtrlListBox_AddString($hListBox, "Musterdad PDK5")
_GUICtrlListBox_EndUpdate($hListBox)
; Die Schleife wiederholt sich, bis der Benutzer die Beenden-Aktion der GUI auslöst
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>_Main
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg
Local $hWndFrom, $iIDFrom, $iCode, $hWndListBox
If Not IsHWnd($hListBox) Then $hWndListBox = GUICtrlGetHandle($hListBox)
$hWndFrom = $ilParam
$iIDFrom = BitAND($iwParam, 0xFFFF) ; Niederwertiges Wort (WORD)
$iCode = BitShift($iwParam, 16) ; Höherwertiges Wort (WORD)
Switch $hWndFrom
Case $hListBox, $hWndListBox
Switch $iCode
Case $LBN_DBLCLK ; Wird gesendet, wenn der Benutzer einen Doppelklick auf einen String in einer ListBox ausführt
; Test MsgBox
; MsgBox(0,"hWndFrom / IDFrom / Code", "hWndFrom / IDFrom / Code: " & $hWndFrom & "---" & $iIDFrom & "---" & $iCode)
local $aItem
$aItem = _GUICtrlListBox_GetCurSel($hListBox) ;Eintrags Position bekommen
MsgBox(4160, "ausgewählt", "Sie haben folgende Auswahl getroffen: " & _GUICtrlListBox_GetText($hListBox, $aItem))
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND
Punkt 2.
Ja du kannst eine .txt Datei erstellen und die mit einem Array über FileReadLine einlesen und dabei deiner Listbox übergeben.