Code : Tout sélectionner
; http://www.autoitscript.com/forum/index.php?showtopic=53730&hl=
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
#include <GUIConstantsEx.au3>
Global $DropFilesArr[1]
Global $FilesAllowedMask[4] = [3, ".txt", ".exe", "D"]
GUICreate("Drop Multiple Files to LV Demo", 500, 400, -1, -1, -1, $WS_EX_ACCEPTFILES+$WS_EX_TOPMOST)
GUIRegisterMsg(0x233, "WM_DROPFILES_FUNC")
GUICtrlCreateLabel("Drag to the List View some file(s)", 60, 20)
$ListView = GUICtrlCreateListView("Col1|Col2|Col3", 50, 50, 400, 300, -1, $WS_EX_CLIENTEDGE)
GUICtrlSendMsg(-1, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_HEADERDRAGDROP, $LVS_EX_HEADERDRAGDROP)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUISetState()
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case -3
Exit
Case $GUI_EVENT_DROPPED
$NotValidExtPath = ""
$ValidExtCount = 0
For $i = 1 To UBound($DropFilesArr)-1
If _IsValidExt($DropFilesArr[$i]) Then
$ValidExtCount += 1
GUICtrlCreateListViewItem($DropFilesArr[$i], $ListView)
Else
$NotValidExtPath &= $DropFilesArr[$i] & @LF
EndIf
Next
If $ValidExtCount > 0 Then GUICtrlSendMsg($ListView, $LVM_SETCOLUMNWIDTH, 0, -1)
If $NotValidExtPath <> "" Then
MsgBox(262144+48, "Attention", "You dropped file(s) with non valid extension/attribute:" _
& @LF & @LF & $NotValidExtPath)
EndIf
EndSwitch
WEnd
Func _IsValidExt($sPath)
For $i = 1 To $FilesAllowedMask[0]
If StringRight($sPath, 4) = $FilesAllowedMask[$i] And _
Not StringInStr(FileGetAttrib($sPath), $FilesAllowedMask[$i]) Then Return True
Next
Return False
EndFunc
Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam)
Local $nSize, $pFileName
Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
For $i = 0 To $nAmt[0] - 1
$nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
$nSize = $nSize[0] + 1
$pFileName = DllStructCreate("char[" & $nSize & "]")
DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", _
DllStructGetPtr($pFileName), "int", $nSize)
ReDim $DropFilesArr[$i + 2]
$DropFilesArr[$i+1] = DllStructGetData($pFileName, 1)
$pFileName = 0
Next
$DropFilesArr[0] = UBound($DropFilesArr)-1
EndFunc