#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
;
Global Const $WM_DROPFILES = 0x233
Global $aDroppedFiles[1]
Global $aIncludeFilesMask[4] = [3, "au3", "txt", "D"] ; "D" это папки
$Form1 = GUICreate("Form1", 153, 133, 412, 300, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_TOPMOST))
GUISetFont(7)
$Button1 = GUICtrlCreateButton("Button1", 8, 8, 41, 33, 0)
$Button2 = GUICtrlCreateButton("Button2", 56, 8, 41, 33, 0)
$Button3 = GUICtrlCreateButton("Button3", 104, 8, 41, 33, 0)
$Button4 = GUICtrlCreateButton("Button4", 8, 48, 41, 33, 0)
$Button5 = GUICtrlCreateButton("Button5", 56, 48, 41, 33, 0)
$Button6 = GUICtrlCreateButton("Button6", 104, 48, 41, 33, 0)
$Button7 = GUICtrlCreateButton("Button7", 8, 88, 41, 33, 0)
$Button8 = GUICtrlCreateButton("Button8", 56, 88, 41, 33, 0)
$Button9 = GUICtrlCreateButton("Button9", 104, 88, 41, 33, 0)
For $i = 1 To 9
GUICtrlSetState(Eval("Button" & $i), $GUI_DROPACCEPTED)
Next
GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES_FUNC")
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $GUI_EVENT_DROPPED
$sNotValidExtPath = ""
$sFilesList = ""
For $i = 1 To UBound($aDroppedFiles)-1
If _DroppedFileIsValidExt($aDroppedFiles[$i]) Then
$sFilesList &= $aDroppedFiles[$i]
Else
$sNotValidExtPath &= $aDroppedFiles[$i] & @CRLF
EndIf
Next
If $sNotValidExtPath <> "" Then
MsgBox(262144+48, "Attention!", _
"You dropped file(s) with non valid extension/attribute:" & @CRLF & @CRLF & $sNotValidExtPath, 0, $Form1)
Else
MsgBox(64, 'Dropped', _
StringFormat('ButtonID: %i, Button Text: %s\n\nDropped files list:\n\n%s', _
@GUI_DropId, GUICtrlRead(@GUI_DropId, 1), $sFilesList), 0, $Form1)
EndIf
EndSwitch
WEnd
Func _DroppedFileIsValidExt($sPath)
If $aIncludeFilesMask[0] <= 0 Then Return True
For $i = 1 To $aIncludeFilesMask[0]
If StringRegExp($sPath, "(?i)^.*\." & $aIncludeFilesMask[$i] & "$") Or _
StringInStr(FileGetAttrib($sPath), $aIncludeFilesMask[$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)
$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