官网早有解决,直接上代码
#RequireAdmin
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
Opt("GuiOnEventMode", 1)
Global $DropFilesArr[1]
Global $FilesAllowedMask[4] = [3, ".txt", ".exe", "D"]
$mainFrm = GUICreate("Drop Multiple Files to LV Demo", 500, 400, -1, -1, -1, $WS_EX_ACCEPTFILES+$WS_EX_TOPMOST)
_ChangeWindowMessageFilterEx($mainFrm, 0x233, 1)
_ChangeWindowMessageFilterEx($mainFrm, $WM_COPYDATA, 1)
_ChangeWindowMessageFilterEx($mainFrm, 0x0049, 1)
GUISetOnEvent($GUI_EVENT_CLOSE, "MainEvents")
GUISetOnEvent($GUI_EVENT_DROPPED, "MainEvents")
GUIRegisterMsg(0x233, "WM_DROPFILES_FUNC")
GUICtrlCreateLabel("Drag to the List View some file(s)", 60, 20)
$ListView = GUICtrlCreateListView("Col1", 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
Sleep(100)
WEnd
Func MainEvents()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_DROPPED
$NotValidExtPath = ""
$ValidExtCount = 0
For $i = 1 To UBound($DropFilesArr)-1
$ValidExtCount += 1
GUICtrlCreateListViewItem($DropFilesArr[$i], $ListView)
Next
If $ValidExtCount > 0 Then GUICtrlSendMsg($ListView, $LVM_SETCOLUMNWIDTH, 0, -1)
EndSwitch
EndFunc
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
Func _ChangeWindowMessageFilterEx($hWnd, $iMsg, $iAction)
Local $aCall = DllCall("user32.dll", "bool", "ChangeWindowMessageFilterEx", _
"hwnd", $hWnd, _
"dword", $iMsg, _
"dword", $iAction, _
"ptr", 0)
If @error Or Not $aCall[0] Then Return SetError(1, 0, 0)
Return 1
EndFunc
|