[au3]#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
Global Const $WM_DROPFILES = 0x0233
Global $aDroppedFiles[1]
GUICreate("支持拖放文件的ListView", 500, 400, -1, -1, -1, $WS_EX_ACCEPTFILES+$WS_EX_TOPMOST)
GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES")
GUICtrlCreateLabel("把文件拖放到ListView看看", 60, 20)
$ListView = GUICtrlCreateListView("Col1|Col2", 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
For $i = 1 To UBound($aDroppedFiles)-1
$file=StringSplit($aDroppedFiles[$i],"\")
$file=$file[$file[0]]
GUICtrlCreateListViewItem($file&"|"&$aDroppedFiles[$i], $ListView)
Next
GUICtrlSendMsg($ListView, $LVM_SETCOLUMNWIDTH, 0, -1)
EndSwitch
WEnd
Func WM_DROPFILES($hWnd, $msgID, $wParam, $lParam)
Local $nSize, $pFileName
Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
$aDroppedFiles = 0
Dim $aDroppedFiles[$nAmt[0]+1]
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)
$aDroppedFiles[0] += 1
$aDroppedFiles[$aDroppedFiles[0]] = DllStructGetData($pFileName, 1)
$pFileName = 0
Next
ReDim $aDroppedFiles[$aDroppedFiles[0]+1]
EndFunc[/au3] |