BUNNY3005,
You need to get the desktop files into an array - the code then adds the matching names to the list. This should work:
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Array.au3>
#include <GuiListBox.au3>
#include <WinAPIDlg.au3>
#include <File.au3>
Global $hGUI, $cInput, $cList, $sPartialData, $asFile
; Create an array full of files
sFile()
$hGUI = GUICreate("Example", 200, 400)
$cInput = GUICtrlCreateInput("", 5, 5, 190, 20)
$cList = GUICtrlCreateList("", 5, 30, 190, 325, BitOR(0x00100000, 0x00200000))
$cButton = GUICtrlCreateButton("Read", 60, 360, 80, 30)
$cUP = GUICtrlCreateDummy()
$cDOWN = GUICtrlCreateDummy()
$cENTER = GUICtrlCreateDummy()
GUISetState(@SW_SHOW, $hGUI)
; Set accelerators for Cursor up/down and Enter
Dim $AccelKeys[3][2] = [["{UP}", $cUP], ["{DOWN}", $cDOWN], ["{ENTER}", $cENTER]]
GUISetAccelerators($AccelKeys)
$iCurrIndex = -1
GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")
While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
Exit
Case $cList
$sChosen = GUICtrlRead($cList)
If $sChosen <> "" Then GUICtrlSetData($cInput, $sChosen)
Case $cButton
If $sPartialData <> "" Then
$sFinal = GUICtrlRead($cInput)
If _ArraySearch($asFile, $sFinal) > 0 Then
MsgBox(0, "Chosen", $sFinal)
EndIf
EndIf
Case $cUP
If $sPartialData <> "" Then
$iCurrIndex -= 1
If $iCurrIndex < 0 Then $iCurrIndex = 0
_GUICtrlListBox_SetCurSel($cList, $iCurrIndex)
EndIf
Case $cDOWN
If $sPartialData <> "" Then
$iTotal = _GUICtrlListBox_GetCount($cList)
$iCurrIndex += 1
If $iCurrIndex > $iTotal - 1 Then $iCurrIndex = $iTotal - 1
_GUICtrlListBox_SetCurSel($cList, $iCurrIndex)
EndIf
Case $cENTER
If $iCurrIndex <> -1 Then
$sText = _GUICtrlListBox_GetText($cList, $iCurrIndex)
GUICtrlSetData($cInput, $sText)
$iCurrIndex = -1
_GUICtrlListBox_SetCurSel($cList, $iCurrIndex)
EndIf
EndSwitch
WEnd
Func CheckInputText()
$sPartialData = "|" ; Start with delimiter so new data always replaces old
Local $sInput = GUICtrlRead($cInput)
If $sInput <> "" Then
For $i = 1 To $asFile[0]
If StringInStr($asFile[$i], $sInput) <> 0 Then $sPartialData &= $asFile[$i] & "|"
Next
GUICtrlSetData($cList, $sPartialData)
EndIf
EndFunc ;==>CheckInputText
Func sFile()
; Get an array of files from the desktop
$asFile = _FileListToArray(@DesktopDir, "*", $FLTA_FILES)
EndFunc ;==>sFile
Func _WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
; If it was an update message from our input
If _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $cInput Then
CheckInputText()
EndIf
EndFunc ;==>_WM_COMMAND
M23