#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListViewConstants.au3>
#include <Array.au3>
Global Const $WM_DROPFILES = 0x233
Global $aDroppedFiles[1]
Global $aIncludeFilesMask = StringSplit(".torrent", "|") ;Разрешённые расширения файлов
Global $iShowInvalidExtsMessage = 1 ;Показывать сообщение о неподдерживаемых расширении файлов
Global $iClipPutInterval = 1000 ;Время ожидания (в миллисекундах) между отправкой файла в буфер обмена
$hGUI = GUICreate("Drop Files GUI", 500, 400, -1, -1, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST))
GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES_FUNC")
GUICtrlCreateLabel('', 0, 0, 500, 400)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUISetState()
While 1
$Msg = GUIGetMsg()
Switch $Msg
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_DROPPED
$sNotValidExtPath = ""
_ArraySort($aDroppedFiles, 1, 1)
For $i = 1 To UBound($aDroppedFiles)-1
If _DroppedFileIsValidExt($aDroppedFiles[$i]) Then
ClipPut(StringRegExpReplace($aDroppedFiles[$i], '^.*\\|\.[^\.]*$', ''))
If $iClipPutInterval Then
Sleep($iClipPutInterval)
EndIf
Else
$sNotValidExtPath &= $aDroppedFiles[$i] & @CRLF
EndIf
Next
If $iShowInvalidExtsMessage And $sNotValidExtPath <> "" Then
MsgBox(262144+48, "Attention!", "You dropped file(s) with non valid extension/attribute:" & @CRLF & @CRLF & $sNotValidExtPath, 0, $hGUI)
EndIf
EndSwitch
WEnd
Func _DroppedFileIsValidExt($sPath)
For $i = 1 To $aIncludeFilesMask[0]
If StringRegExp($sPath, '(?i)\Q' & $aIncludeFilesMask[$i] & '\E$') Or StringInStr(FileGetAttrib($sPath), $aIncludeFilesMask[$i]) Then
Return True
EndIf
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)
$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