Code : Tout sélectionner
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
Global $Form1 = GUICreate("Form1", 615, 438, 192, 124, -1, $WS_EX_ACCEPTFILES)
GUISetBkColor(0xFFFFFF)
GUICtrlCreateLabel("Dossier à lister", 20, 20, 100, 20)
GUICtrlSetFont(-1, 9, 400, 0, "comic sans ms")
$dirlist = GUICtrlCreateInput("", 140, 20, 200, 20)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
$listBT = GUICtrlCreateButton("Lister", 360, 20, 80, 20)
$DirList_LV = GUICtrlCreateListView("", 140, 60, 200, 200)
_GUICtrlListView_AddColumn($DirList_LV, "liste des fichiers", 500)
GUICtrlCreateGroup("Actions", 360, 150, 100, 110, $WS_BORDER)
$OpenSel = GUICtrlCreateButton("Ouvrir", 370, 170, 80, 20)
$MoveSel = GUICtrlCreateButton("Déplacer", 370, 200, 80, 20)
$DelSel = GUICtrlCreateButton("Supprimer", 370, 230, 80, 20)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $listBT
_List()
Case $OpenSel
ShellExecute(StringTrimRight(GUICtrlRead(GUICtrlRead($DirList_LV)), 1))
Case $DelSel
FileDelete(GUICtrlRead($dirlist) & "\" & StringTrimRight(GUICtrlRead(GUICtrlRead($DirList_LV)), 1))
My_GUICtrlListView_DeleteItem($DirList_LV, StringTrimRight(GUICtrlRead(GUICtrlRead($DirList_LV)), 1))
EndSwitch
WEnd
Func _List()
_GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($DirList_LV))
Local $FileList = _FileListToArray(GUICtrlRead($dirlist))
$Result = UBound($FileList) - 1
For $i = 1 To $Result
If Not @error Then
GUICtrlCreateListViewItem($FileList[$i], $DirList_LV)
_GUICtrlListView_SetItemState($DirList_LV, _GUICtrlListView_GetItemCount($DirList_LV) - 1, 1, 1)
_GUICtrlListView_Scroll($DirList_LV, 0, (_GUICtrlListView_GetItemCount($DirList_LV) - 1) * 14)
EndIf
Next
EndFunc ;==>_List
Func My_GUICtrlListView_DeleteItem($hWnd, $item = -1)
If Not IsHWnd($hWnd) Then $hWnd = GUICtrlGetHandle($hWnd)
If $item = -1 Then $item = _GUICtrlListView_GetSelectedIndices($hWnd)
_GUICtrlListView_DeleteItem($hWnd, $item)
EndFunc ;==>My_GUICtrlListView_DeleteItem