Jump to content

Drop Area For Files, Some questions?


Recommended Posts

I was thinking about a drop area on a gui for a file possibly rar file

Can i capture the filename from a drop area when the file is dropped on it?

Does it require a special button/code or something to do it?

Are there any limitations?

I was going to do the normal popup box to choose the file but i wondered if a drop area might be ok for the same thing.

Link to comment
Share on other sites

I remember I setup some gui input controls to accept drag and drop (to store filename and or paths).  I can find the code if that is something you're interested in.

This looks like an example of something that might work, it's been a long time since I've done anything like this.

Edited by Xandy
Link to comment
Share on other sites

Did you search? Because honestly you're not the first person to ask this question and surely won't be the last.

In spite of that, I will create some clean workable code for you. A simple drag and drop file(s) on a label using a custom API. See the Example() function of how to use and please please please read the comments.

#include <APIConstants.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIEx.au3>

; Internal array, DO NOT USE directly. Instead call GetDropFiles() & IsValidDrop()
Global $g_aDropFiles[0]

Example()

Func Example()
    Local $hGUI = GUICreate('', 500, 500, -1, -1, -1, $WS_EX_ACCEPTFILES)

    ; IMPORTANT: If the system is using limited access rights
    If IsAdmin() Then _WinAPI_ChangeWindowMessageFilterEx($hGUI, $WM_DROPFILES, $MSGFLT_ALLOW)
    If IsAdmin() Then _WinAPI_ChangeWindowMessageFilterEx($hGUI, $WM_COPYGLOBALDATA, $MSGFLT_ALLOW)

    ; Create a label that is transparent which will accept 'drop' events.
    GUICtrlCreateLabel('Drop Files Here...', 0, 0, 500, 500)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlSetResizing(-1, $GUI_DOCKALL)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)

    GUIRegisterMsg($WM_DROPFILES, 'WM_DROPFILES')
    GUISetState(@SW_SHOW, $hGUI)

    Local $aDropped = 0
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $GUI_EVENT_DROPPED
                ; This always returns a valid array regardless of an error
                $aDropped = GetDropFiles()

                ; Was a valid drop?
                If IsValidDrop() Then
                    _ArrayDisplay($aDropped)
                EndIf

                ; Write the list of files to the console
                For $i = 1 To UBound($aDropped) - 1 ; $i is 1, because we need to skip the count in the first element. By iterating over the array this way, we avoid "out of bounds" errors
                    ConsoleWrite('File ' & $i & ' => ' & $aDropped[$i] & @CRLF)
                Next

                ; Empty line
                ConsoleWrite(@CRLF)

        EndSwitch
    WEnd

    ; Clean up the resources
    GUIDelete($hGUI)
EndFunc   ;==>Example

; Get the dropped list of files. NOTE: Destroys the global varibale on return
Func GetDropFiles()
    Local Const $aEmpty[1] = [0] ; Empty array
    Local $aReturn = $g_aDropFiles
    $g_aDropFiles = $aEmpty ; Destroy the global variable with the empty array
    Return $aReturn
EndFunc   ;==>GetDropFiles

; Use to determine if the drop was valid
Func IsValidDrop()
    Return UBound($g_aDropFiles) > 0
EndFunc   ;==>IsValidDrop

Func WM_DROPFILES($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $lParam
    If $iMsg = $WM_DROPFILES Then
        $g_aDropFiles = _WinAPI_DragQueryFileEx($wParam)
        If Not UBound($g_aDropFiles) Then
            Local Const $aError[1] = [0] ; Empty array
            $g_aDropFiles = $aError ; Set with the empty array
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DROPFILES
Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

I remember I setup some gui input controls to accept drag and drop (to store filename and or paths).  I can find the code if that is something you're interested in.

This looks like an example of something that might work, it's been a long time since I've done anything like this.

​The code is outdated, as the functions are included in the UDF library. Therefore re-use code, don't create new.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

I would not mind perfecting this as well.

I use a lot of "right click" scripts and that works fine but for some things drag and drop would work great too so that I do not overpopulate the right click context menus. 

 

Edit:

For a single item drag/drop seems I got enough to get done what I would need to get done.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 315, 89, 192, 124, -1, $WS_EX_ACCEPTFILES) ;0x00000010
$Input1 = GUICtrlCreateInput("Input1", 40, 32, 121, 21)
GUICtrlSetState(-1, $GUI_DROPACCEPTED) ;8
$Label1 = GUICtrlCreateLabel("Drag Here!", 72, 8, 56, 17)
$Button1 = GUICtrlCreateButton("GO!", 192, 24, 75, 25)
GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            ExitLoop

    EndSwitch
WEnd

MsgBox(0, "", GUICtrlRead($Input1))

Next step for me would be find how to remove the "OK" button and have it exit loop when the file is dragged.  I assume a GUICtrlRead($Input1) <> "Input1" Then ExitLoop would work.

 

Edit: yes that works, now how to keep the GUI open so I can drag more than one file without re-launching the gui :)

Edited by ViciousXUSMC
Link to comment
Share on other sites

This seems to work :) do not know if its a terrible way to code it.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 315, 89, 192, 124, -1, $WS_EX_ACCEPTFILES) ;0x00000010
$Input1 = GUICtrlCreateInput("Input1", 40, 32, 121, 21)
GUICtrlSetState(-1, $GUI_DROPACCEPTED) ;8
$Label1 = GUICtrlCreateLabel("Drag Here!", 72, 8, 56, 17)
;Do Not Need Button Anylonger
;$Button1 = GUICtrlCreateButton("GO!", 192, 24, 75, 25)
GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###


Loop()


Func Loop()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        ;Case $Button1
            ;ExitLoop
    EndSwitch

    If GUICtrlRead($Input1) <> "Input1" Then ExitLoop
WEnd

;Action to take on file each time dragged, in this case just a msgbox
MsgBox(0, "", GUICtrlRead($Input1))
GUICtrlSetData($Input1, "Input1")
Loop()
EndFunc

 

Link to comment
Share on other sites

Well it could be better. At least you're using named constants instead of magic values.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Well this is lively :) i was asking questions but thanks for the excellent answers

One question remains unanswered though

Does a dropbox have limitaions? is there a max amount of files it can handle? or size etc
knowing AutoIt it will prob be large but i was curious.

Being as im using it to isolate one file from many after they are dropped it probably wont matter to me anyway but i was just curious

ive started like this using guinness example

#include <APIConstants.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIEx.au3>
#include <StaticConstants.au3>
#include <File.au3> ; For Pathsplit

; Internal array, DO NOT USE directly. Instead call GetDropFiles() & IsValidDrop()
Global $g_aDropFiles[0]

Example()

Func Example()
    Local $hGUI = GUICreate('', 500, 500, -1, -1, -1, $WS_EX_ACCEPTFILES)
    Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = ""
    ; Create a label that is transparent which will accept 'drop' events.
    GUICtrlCreateButton('Drop Files Here', 100, 100, 300, 300)
    GUICtrlSetBkColor(-1, 0xE0FFFF)
;~  GUICtrlSetResizing(-1, $GUI_DOCKALL)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)

    GUIRegisterMsg($WM_DROPFILES, 'WM_DROPFILES')
    GUISetState(@SW_SHOW, $hGUI)

    Local $aDropped = 0
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $GUI_EVENT_DROPPED
                $aDropped = GetDropFiles() ; This always returns a valid array regardless of an error
                If IsValidDrop() Then
                    _ArraySort($aDropped); Sort the array so the first file is at the top
                    _ArrayDisplay($aDropped)
                    $FirstFile = $aDropped[1]; Select only the first file for the name
                    ConsoleWrite($FirstFile & @CRLF)
                    $FileName = _PathSplit($FirstFile,$sDrive, $sDir, $sFilename, $sExtension) ; split the name from the path
                EndIf

                ; Write the list of files to the console
;~              For $i = 1 To UBound($aDropped) - 1 ; $i is 1, because we need to skip the count in the first element. By iterating over the array this way, we avoid "out of bounds" errors
;~                  ConsoleWrite('File ' & $i & ' => ' & $aDropped[$i] & @CRLF)
;~              Next
;~              ConsoleWrite(@CRLF)
        EndSwitch
    WEnd

    GUIDelete($hGUI)
EndFunc   ;==>Example

; Get the dropped list of files
Func GetDropFiles()
    Return $g_aDropFiles
EndFunc   ;==>GetDropFiles

; Use to determine if the drop was valid
Func IsValidDrop()
    Return UBound($g_aDropFiles) > 0
EndFunc   ;==>IsValidDrop

Func WM_DROPFILES($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $lParam
    If $iMsg = $WM_DROPFILES Then
        $g_aDropFiles = _WinAPI_DragQueryFileEx($wParam)
        If Not UBound($g_aDropFiles) Then
            Local Const $aError[0] ; Empty array
            $g_aDropFiles = $aError ; Set with the empty array
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DROPFILES

then i shall use the pieces to determine files i need etc

Early days i shall get time later in the week to start working on it

 

Many thanks

Edited by Chimaera
Updated as per guinness request
Link to comment
Share on other sites

@ViciousXUSMC,

F.Y.I. 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 315, 89, 192, 124, -1, $WS_EX_ACCEPTFILES) ;0x00000010
$Input1 = GUICtrlCreateInput("Input1", 40, 32, 121, 21)
GUICtrlSetState(-1, $GUI_DROPACCEPTED) ;8
$Label1 = GUICtrlCreateLabel("Drag Here!", 72, 8, 56, 17)
;Do Not Need Button Anylonger

;$Button1 = GUICtrlCreateButton("GO!", 192, 24, 75, 25)
GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###


;Loop()


;Func Loop()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg

        Case $GUI_EVENT_CLOSE
            Exit
        Case $gui_event_dropped ;   <--------- instead of reading the input control just monitor the drop event
            MsgBox(0, "", GUICtrlRead($Input1))
            GUICtrlSetData($Input1, "Input1")

            ;Case $Button1
            ;ExitLoop

    EndSwitch



    ;If GUICtrlRead($Input1) <> "Input1" Then ExitLoop

WEnd



;Action to take on file each time dragged, in this case just a msgbox

;MsgBox(0, "", GUICtrlRead($Input1))
;GUICtrlSetData($Input1, "Input1")
;Loop()
;EndFunc   ;==>Loop

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

The only limitation is how many elements an array can have. Check the help file for the limits.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Oh and I guess you have a small test script, therefore could you post it all instead of a small snippet. It's just that the code you posted makes no sense to a new user, without an overall view of the code beforehand. Plus think how you would feel if you came across a post where you knew it was useful, but a huge chunk of code was missing.

This is why I always post runnable code, as it helps everyone to understand. Thanks.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

@ViciousXUSMC,

F.Y.I. 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 315, 89, 192, 124, -1, $WS_EX_ACCEPTFILES) ;0x00000010
$Input1 = GUICtrlCreateInput("Input1", 40, 32, 121, 21)
GUICtrlSetState(-1, $GUI_DROPACCEPTED) ;8
$Label1 = GUICtrlCreateLabel("Drag Here!", 72, 8, 56, 17)
;Do Not Need Button Anylonger

;$Button1 = GUICtrlCreateButton("GO!", 192, 24, 75, 25)
GUISetState(@SW_SHOW)

#EndRegion ### END Koda GUI section ###


;Loop()


;Func Loop()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg

        Case $GUI_EVENT_CLOSE
            Exit
        Case $gui_event_dropped ;   <--------- instead of reading the input control just monitor the drop event
            MsgBox(0, "", GUICtrlRead($Input1))
            GUICtrlSetData($Input1, "Input1")

            ;Case $Button1
            ;ExitLoop

    EndSwitch



    ;If GUICtrlRead($Input1) <> "Input1" Then ExitLoop

WEnd



;Action to take on file each time dragged, in this case just a msgbox

;MsgBox(0, "", GUICtrlRead($Input1))
;GUICtrlSetData($Input1, "Input1")
;Loop()
;EndFunc   ;==>Loop

kylomas

​Hey thanks, that is much cleaner.  

Such a big difference in can make just to know a few extra pieces of information about AutoIT.  Also I was having brain malfunction for some reason yesterday trying to think how to make the loop repeat so I was self referencing a function and I think thats a bad bad idea usually.  Even my way it could have been cleaner like this.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 315, 89, 192, 124, -1, $WS_EX_ACCEPTFILES) ;0x00000010
$Input1 = GUICtrlCreateInput("", 40, 32, 121, 21)
GUICtrlSetState(-1, $GUI_DROPACCEPTED) ;8
$Label1 = GUICtrlCreateLabel("Drag Here!", 72, 8, 56, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        ;Case $Button1
            ;ExitLoop
    EndSwitch

    If GUICtrlRead($Input1) <> "" Then
        ;Action to take on file each time dragged, in this case just a msgbox
        $data =  GUICtrlRead($Input1)
        $aSplitData = StringSplit($data, "|", 2)
        If Not IsArray($aSplitData) Then
        MsgBox(0, "", GUICtrlRead($Input1))
        Else
        ;_ArrayDisplay($aSplitData)
        For $i = 0 to UBound($aSplitData) - 1
        MsgBox(0, "", $aSplitData[$i])
        Next
        EndIf
        GUICtrlSetData($Input1, "")
        EndIf
WEnd

 

My Ultimate end result was this however.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 315, 89, 192, 124, -1, $WS_EX_ACCEPTFILES) ;0x00000010
$Input1 = GUICtrlCreateInput("", 40, 32, 121, 21)
GUICtrlSetState(-1, $GUI_DROPACCEPTED) ;8
$Label1 = GUICtrlCreateLabel("Drag Here!", 72, 8, 56, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_DROPPED
            ;Action to take on file each time dragged, in this case just a msgbox
            $data =  GUICtrlRead($Input1)
            $aSplitData = StringSplit($data, "|", 2)
            If Not IsArray($aSplitData) Then
            MsgBox(0, "", GUICtrlRead($Input1))
            Else
            ;_ArrayDisplay($aSplitData)
            For $i = 0 to UBound($aSplitData) - 1
            MsgBox(0, "", $aSplitData[$i])
            Next
            EndIf
            GUICtrlSetData($Input1, "")
    EndSwitch
WEnd

Edit: And yeah when I saw what happens to my msgbox when dragging in multiple files it was not too hard to figure out how to toss that into an array for a multi-drag & drop (plus the help file example was great)

Edited by ViciousXUSMC
Link to comment
Share on other sites

@Chimaera, ViciousXUSC,

Dropped files are always delimited with a separator char, even if only one is dropped.  Therefore the code can be simplified like this

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

local $gui010 = guicreate('Drop Example',200,100)
                guisetstyle(-1,$WS_EX_ACCEPTFILES,$gui010)
local $inp010 = guictrlcreateinput('',10,30,180,20)
                guictrlsetstate($inp010, $GUI_DROPACCEPTED)
local $inp020 = guictrlcreateinput('',10,70,180,20)
                guictrlsetstate($inp020, $GUI_DROPACCEPTED)
guisetstate()

local $aFiles



while 1
    switch guigetmsg()
        case $gui_event_close
            Exit
        case $gui_event_dropped
            ConsoleWrite('Files dropped on ' & ( @GUI_DropId = $inp010  ? '$inp010:' & @CRLF : '$inp020:' & @CRLF ))
            $aFiles = stringsplit(guictrlread(@GUI_DROPID),'|',3)
            for $1 = 0 to ubound($aFiles) - 1
                ConsoleWrite(@tab & $aFiles[$1] & @CRLF)
            next
    EndSwitch

WEnd

kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Link to comment
Share on other sites

@All, Perhaps everyone should analyse this code and see what I changed. Plus my version above is better as it's not limited to input controls only.

#include <GUIConstantsEx.au3>
#include <StringConstants.au3>
#include <WindowsConstants.au3>

; Improved by using the correct casing for constants as well as best practices in AutoIt
Example()

Func Example()
    Local $hGUI = GUICreate('Drop Example', 200, 100, -1, -1, -1, $WS_EX_ACCEPTFILES) ; Set the ExStyle on GUI creation
    Local $idInput1 = GUICtrlCreateInput('', 10, 30, 180, 20)
    GUICtrlSetState($idInput1, $GUI_DROPACCEPTED)
    Local $idInput2 = GUICtrlCreateInput('', 10, 70, 180, 20)
    GUICtrlSetState($idInput2, $GUI_DROPACCEPTED)
    GUISetState(@SW_SHOW, $hGUI)

    Local $aFiles = 0
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop ; Don't Exit, ExitLoop

            Case $GUI_EVENT_DROPPED
                ConsoleWrite('Files dropped on ' & _
                        '$idInput' & ((@GUI_DropId == $idInput1) ? '1' : '2') & @CRLF)
 ; Proper usage

                $aFiles = StringSplit(GUICtrlRead(@GUI_DropId), '|', $STR_NOCOUNT)
 ; No need for entire split as it's a pipe char
                For $i = 0 To UBound($aFiles) - 1
 ; Common practice to use $i NOT $l
                    ConsoleWrite(@TAB & $aFiles[$i] & @CRLF)
                Next

        EndSwitch
    WEnd

    GUIDelete($hGUI) ; Tidy up the GUI resources
EndFunc   ;==>Example

I admit we all have our unique styles when it comes to programming, but in the real world when you work as a developer you have to meet the common standards used across all languages such as i being used as an iterator variable.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

I have updated my code above. Thanks.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Thank God I'm Retired!!!

​Haha, okay! Now I understand :P

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Using guinness earlier code i have moved on to here

#include <APIConstants.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIEx.au3>
#include <StaticConstants.au3>
#include <File.au3> ; For Pathsplit

; Internal array, DO NOT USE directly. Instead call GetDropFiles() & IsValidDrop()
Global $g_aDropFiles[0]

Example()

Func Example()
    Local $hGUI = GUICreate('', 500, 500, -1, -1, -1, $WS_EX_ACCEPTFILES)
    Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = ""
    ; Create a label that is transparent which will accept 'drop' events.
    GUICtrlCreateButton('Drop Files Here', 100, 100, 300, 300)
    GUICtrlSetBkColor(-1, 0xE0FFFF)
;~  GUICtrlSetResizing(-1, $GUI_DOCKALL)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)

    GUIRegisterMsg($WM_DROPFILES, 'WM_DROPFILES')
    GUISetState(@SW_SHOW, $hGUI)

    Local $aDropped = 0
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $GUI_EVENT_DROPPED
                $aDropped = GetDropFiles() ; This always returns a valid array regardless of an error
                If IsValidDrop() Then
                    _ArraySort($aDropped); Sort the array so the first file is at the top
                    _ArrayDisplay($aDropped) ; <<<<<<<<<< error checking
                    $FirstFile = $aDropped[1]; Select only the first file for the name
                    $FileSplit = _PathSplit($FirstFile,$sDrive, $sDir, $sFilename, $sExtension) ; split the name from the path
                    $sPath = $sDrive & $sDir
                    ConsoleWrite('Path = ' & $sPath & @CRLF)
                    ConsoleWrite('Drive = ' & $sDrive & @CRLF & 'Dir = ' & $sDir & @CRLF & 'Filename = ' & $sFilename & @CRLF & 'Extension = ' & $sExtension & @CRLF) ; <<<<<<<<<< error checking
                    ;----------------------------------------
                    If $sExtension = '.par2' Or $sExtension = '.par3' Then
                    Local $FindFiles = _FileListToArrayRec( $sPath, '*' & $sFilename & $sExtension, 1, 0)
                        _ArrayDisplay($FindFiles, ".Par Files")
                    If IsArray($FindFiles) Then
                        For $i = 1 To $FindFiles[0]
                            FileMove($sPath & $FindFiles[$i], $sPath & $sFilename & "\", 9)
                            Sleep(100)
                        Next
                    EndIf
;~                      _Repair()
                    ElseIf $sExtension = '.rar' Then
                    Local $FindFiles = _FileListToArrayRec( $sPath, '*' & StringTrimRight($sFilename, 2) & '*', 1, 0)
                        _ArrayDisplay($FindFiles, ".Rar Files")
                    If IsArray($FindFiles) Then
                        For $i = 1 To $FindFiles[0]
                            FileMove($sPath & $FindFiles[$i], $sPath & $sFilename & "\", 9)
                            Sleep(100)
                        Next
                    EndIf
;~                      straight to extract
                    ElseIf $sExtension = '.zip' Or $sExtension = '.7z' Then
                    Local $FindFiles = _FileListToArrayRec( $sPath, '*' & StringTrimRight($sFilename, 2) & '*', 1, 0)
                        _ArrayDisplay($FindFiles, ".Zip/7z Files")
                    If IsArray($FindFiles) Then
                        For $i = 1 To $FindFiles[0]
                            FileMove($sPath & $FindFiles[$i], $sPath & $sFilename & "\", 9)
                            Sleep(100)
                        Next
                    EndIf
;~                      straight to extract
                    Else
                        MsgBox(64, 'File Error', 'Unknown File Type')
                    EndIf
                EndIf
        EndSwitch
    WEnd

    GUIDelete($hGUI)
EndFunc   ;==>Example

; Get the dropped list of files
Func GetDropFiles()
    Return $g_aDropFiles
EndFunc   ;==>GetDropFiles

; Use to determine if the drop was valid
Func IsValidDrop()
    Return UBound($g_aDropFiles) > 0
EndFunc   ;==>IsValidDrop

Func WM_DROPFILES($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $lParam
    If $iMsg = $WM_DROPFILES Then
        $g_aDropFiles = _WinAPI_DragQueryFileEx($wParam)
        If Not UBound($g_aDropFiles) Then
            Local Const $aError[0] ; Empty array
            $g_aDropFiles = $aError ; Set with the empty array
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_DROPFILES

So its progressing slowly :)

The only thing i cant quite work out is how to allow for the fact if they add 2 diff sets of archives at the same time.
It finds both but it doesnt extract the diff sets to folders only the first one

 

Edited by Chimaera
Link to comment
Share on other sites

I updated GetDropFiles(). See above.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...