Champak Posted November 17, 2011 Share Posted November 17, 2011 I can't get the drag and drop to work, could I get some help please. expandcollapse popup#Include <File.au3> #Include <Array.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) ;Opt("OnExitFunc", "_OnAutoItExit") ;#cs Global $ASOURCE, $SetPath, $szDrive, $szDir, $szFName, $szExt GUICreate("Infiniti M35X", 200, 200) $GUI_FindPath = GUICtrlCreateButton("Playlist", 15, 15, 70, 50);, $BS_ICON) GUICtrlSetOnEvent($GUI_FindPath, "_FindFile") $GUI_SetPath = GUICtrlCreateButton("Destination", 115, 15, 70, 50);, $BS_ICON) GUICtrlSetOnEvent($GUI_SetPath, "_SetPath") $GUI_Path = GUICtrlCreateLabel("", 15, 70, 170, 75) GUICtrlSetState($GUI_Path, $GUI_DROPACCEPTED) GUISetOnEvent($GUI_EVENT_DROPPED, "_FindFile") GUICtrlSetBkColor($GUI_Path, 0x00ff00) $GUI_FilePath = GUICtrlCreateLabel("", 15, 150, 170, 40) GUICtrlSetBkColor($GUI_FilePath, 0xff0000) GUISetOnEvent($GUI_EVENT_CLOSE, '_onClose') GUISetState() While 1 Sleep(100) WEnd Func _onClose() Exit EndFunc Func _FindFile() If $SetPath = "" Then MsgBox(0,"Destination Path Not Set", "Please set a destination path before proceeding.") Else $FindPath = FileOpenDialog("Playlist", "C:\", "All (*.m3u)") If @error = 1 Then MsgBox(0,"Unknown File", "Unable to set file") Else _Create($FindPath) EndIf EndIf EndFunc Func _SetPath() $SetPath = FileSelectFolder("Set Path Of Files", "") EndFunc Func _Create($Found) _FileReadToArray($Found, $ASOURCE) ;_ArrayDisplay($ASOURCE) ;MsgBox(0,0,$ASOURCE[0]) ;Delete blank spaces in array For $I = $ASOURCE[0] To 0 Step -1 If $ASOURCE[$I] = "" Then _ArrayDelete($ASOURCE, $I) Next ;Delete unneded elements in the beginning from array _ArrayDelete($ASOURCE, 0) _ArrayDelete($ASOURCE, 1) ;Delete #EXF entries in array For $I = UBound($ASOURCE) -2 To 0 Step -2 _ArrayDelete($ASOURCE, $I) Next ;Copy files and set modified date time stamp For $I = 0 To UBound($ASOURCE) - 1 FileCopy($ASOURCE[$I], $SetPath) $TestPath = _PathSplit($ASOURCE[$I], $szDrive, $szDir, $szFName, $szExt) GUICtrlSetData($GUI_FilePath, " Progress: " & $I & " of " & UBound($ASOURCE) & @CRLF & " " & $szFName & $szExt) FileSetTime ( $SetPath & "\" & $szFName & $szExt, "" ) Sleep(100) Next GUICtrlSetData($GUI_FilePath, " Progress: " & $I & " of " & UBound($ASOURCE) & @CRLF & " Complete") EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 17, 2011 Moderators Share Posted November 17, 2011 Champak,You need to set the $WS_EX_ACCEPTFILES extended style when you create the GUI. When I set that style:GUICreate("Infiniti M35X", 200, 200, Default, Default, Default, $WS_EX_ACCEPTFILES)I can drop on the green label and the correct folder/filename is returned in @GUI_DRAGFILE. However, where in the script do you want to use the dropped value because I see no sign of it at the moment. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Champak Posted November 17, 2011 Author Share Posted November 17, 2011 OK, I fixed that thanks, however, for some reason when I use the drag and drop function, and then the script goes into reading the file into an array, the script is unable to open the file. But when I directly open it with the button, it happens with no problem. Why is the drag and drop function preventing the _FileReadToArray from working? expandcollapse popup#Include <File.au3> #Include <Array.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) ;Opt("OnExitFunc", "_OnAutoItExit") ;#cs Global $ASOURCE, $SetPath, $szDrive, $szDir, $szFName, $szExt GUICreate("Infiniti M35X", 200, 200, Default, Default, Default, $WS_EX_ACCEPTFILES) $GUI_FindPath = GUICtrlCreateButton("Playlist", 15, 15, 70, 50);, $BS_ICON) GUICtrlSetOnEvent($GUI_FindPath, "_FindFile") $GUI_SetPath = GUICtrlCreateButton("Destination", 115, 15, 70, 50);, $BS_ICON) GUICtrlSetOnEvent($GUI_SetPath, "_SetPath") $GUI_Path = GUICtrlCreateLabel("", 15, 70, 170, 75) GUICtrlSetState($GUI_Path, $GUI_DROPACCEPTED) ; GUISetOnEvent($GUI_EVENT_DROPPED, "_FindFile") GUICtrlSetBkColor($GUI_Path, 0x00ff00) $GUI_FilePath = GUICtrlCreateLabel("", 15, 150, 170, 40) GUICtrlSetBkColor($GUI_FilePath, 0xff0000) GUISetOnEvent($GUI_EVENT_CLOSE, '_onClose') GUIRegisterMsg(0x233, "On_WM_DROPFILES") GUISetState() While 1 Sleep(100) WEnd Func _evDroppedFiles(ByRef $dFiles) local $x, $files; For $x = 0 To UBound($dFiles)-1 $files &= $dFiles[$x] & @CRLF Next MsgBox(64, 'func1', StringTrimRight($files, 2)); _Create($files) EndFunc Func On_WM_DROPFILES($hWnd, $Msg, $wParam, $lParam) Local $tDrop, $i, $aRet, $iCount; ;get file count $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "ptr", $wParam, "uint", -1, "ptr", 0, "uint", 0 ) $iCount = $aRet[0] ;get file paths local $aDraggedFiles[$iCount]; For $i = 0 To $iCount-1 $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "ptr", $wParam, "uint", $i, "ptr", 0, "uint", 0) Local $tDrop = DllStructCreate("wchar[" & $aRet[0]+1 & "]") $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "ptr", $wParam, "uint", $i, "ptr", DllStructGetPtr($tDrop), "uint", $aRet[0]+1) $aDraggedFiles[$i] = DllStructGetData($tDrop, 1); Next ;finalize DllCall("shell32.dll", "int", "DragFinish", "ptr", $wParam) Return _evDroppedFiles($aDraggedFiles); EndFunc Func _onClose() Exit EndFunc Func _FindFile() If $SetPath = "" Then MsgBox(0,"Destination Path Not Set", "Please set a destination path before proceeding.") Else $FindPath = FileOpenDialog("Playlist", "C:", "All (*.m3u)") If @error = 1 Then MsgBox(0,"Unknown File", "Unable to set file") Else _Create($FindPath) EndIf EndIf EndFunc Func _SetPath() $SetPath = FileSelectFolder("Set Path Of Files", "") EndFunc Func _Create($Found) ;ConsoleWrite($Found) _FileReadToArray($Found, $ASOURCE) If @error Then ConsoleWrite(@CR & @error & @CR) ;_ArrayDisplay($ASOURCE) ;MsgBox(0,0,$ASOURCE[0]) ;Delete blank spaces in array For $I = $ASOURCE[0] To 0 Step -1 If $ASOURCE[$I] = "" Then _ArrayDelete($ASOURCE, $I) Next ;Delete unneded elements in the beginning from array _ArrayDelete($ASOURCE, 0) _ArrayDelete($ASOURCE, 1) ;Delete #EXF entries in array For $I = UBound($ASOURCE) -2 To 0 Step -2 _ArrayDelete($ASOURCE, $I) Next ;Copy files and set modified date time stamp For $I = 0 To UBound($ASOURCE) - 1 FileCopy($ASOURCE[$I], $SetPath) $TestPath = _PathSplit($ASOURCE[$I], $szDrive, $szDir, $szFName, $szExt) GUICtrlSetData($GUI_FilePath, " Progress: " & $I & " of " & UBound($ASOURCE) & @CRLF & " " & $szFName & $szExt) FileSetTime ( $SetPath & "" & $szFName & $szExt, "" ) Sleep(100) Next GUICtrlSetData($GUI_FilePath, " Progress: " & $I & " of " & UBound($ASOURCE) & @CRLF & " Complete") EndFunc Link to comment Share on other sites More sharing options...
kylomas Posted November 18, 2011 Share Posted November 18, 2011 (edited) Champak,Because you are not doing anything with it, as Melba said. $gui_path contains the filename for the drag/dropkylomasedit: spellingEdit: Belay my last, sorry... Edited November 18, 2011 by 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 More sharing options...
kylomas Posted November 18, 2011 Share Posted November 18, 2011 Champak, Search on 'drag and drop with uac' there is an excellent example of managing a drag and drop filelist, just adapt it to your copy code... don't know how to post links from other posts or I would... 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 More sharing options...
jchd Posted November 18, 2011 Share Posted November 18, 2011 kylomas, In the top right corner of each post you can right click on #??? and copy the link. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
kylomas Posted November 18, 2011 Share Posted November 18, 2011 (edited) @jhcd, thanks @champak, Consider the following technique for dropping file(s): #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <array.au3> local $files = '' local $gui010 = GUICreate("Copy from Drag and Drop to Edit Control", 800, 500, -1, -1, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE)) local $edit010 = GUICtrlCreateEdit("", 100, 100, 500, 300,$es_readonly) GUICtrlSetState($edit010, $GUI_DROPACCEPTED) GUISetState() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_DROPPED Switch @GUI_DropId Case $edit010 _copyfiles(guictrlread($edit010)) EndSwitch EndSwitch WEnd func _copyfiles($str) local $a_files = stringsplit($str,@crlf,1) ; $a_files contains a crlf delimited list of fully qualified file names _arraydisplay($a_files) endfunc for me this is more strightforward than using a DLL, mostly because I do not understand PC program architecture, yet. Edited November 18, 2011 by 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 More sharing options...
Champak Posted November 27, 2011 Author Share Posted November 27, 2011 Thats great, thanks, but the problem is i need it in an onevent function because thats how the rest of my script is built, so this wont work. any other ideas? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 27, 2011 Moderators Share Posted November 27, 2011 Champak,Just add a GUISetOnEvent function to react to the $GUI_EVENT_DROPPED message: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <array.au3> Opt("GUIOnEventMode", 1) Local $files = '' Local $gui010 = GUICreate("Copy from Drag and Drop to Edit Control", 800, 500, -1, -1, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE)) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetOnEvent($GUI_EVENT_DROPPED, "_Dropped") Local $edit010 = GUICtrlCreateEdit("", 100, 100, 500, 300, $es_readonly) GUICtrlSetState($edit010, $GUI_DROPACCEPTED) GUISetState() While 1 Sleep(10) WEnd Func _Dropped() Switch @GUI_DropId Case $edit010 _copyfiles(GUICtrlRead($edit010)) EndSwitch EndFunc Func _Exit() Exit EndFunc Func _copyfiles($str) Local $a_files = StringSplit($str, @CRLF, 1) ; $a_files contains a crlf delimited list of fully qualified file names _ArrayDisplay($a_files) EndFunc ;==>_copyfilesM23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Champak Posted November 27, 2011 Author Share Posted November 27, 2011 i actually tried that before. the problem with that is i'm using an image (originally a label but premise still the same) as the drop location so the read function wont work. so beyond the original onevent way i tried i dont know how to pass the file location through on an image. If this is the only way, i guess it is what it is...just hoping it isnt. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 27, 2011 Moderators Share Posted November 27, 2011 Champak, i'm using an image [...] as the drop locationThen why on earth did you post an example with an edit control? Do you think I enjoy wasting my time writing scripts that do not help you solve your problem? If you want to drop on a picture then you need to look for the WM_DROPFILES message from the GUI and then make sure that the cursor is over the pic control when the drop happens: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <array.au3> Opt("GUIOnEventMode", 1) ; This is the list of files dropped Global $aDrop_List ; Create the GUI to accept files $gui010 = GUICreate("Copy from Drag and Drop to Edit Control", 800, 500, -1, -1, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE)) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") ; Create the pic control - notice the name of the image I used ;) $hPic = GUICtrlCreatePic("M:ProgramAu3 ScriptsImagesFacepalm.jpg", 100, 100, 500, 300) ; Now create a dummy control to action the "dropped" function $hDrop_Dummy = GUICtrlCreateDummy() GUICtrlSetOnEvent(-1, "_copyfiles") GUISetState() ; Register $WM_DROPFILES function to detect drops on the GUI GUIRegisterMsg(0x233, "On_WM_DROPFILES") ; $WM_DROPFILES While 1 Sleep(10) WEnd Func _Exit() Exit EndFunc ;==>_Exit Func _copyfiles() _ArrayDisplay($aDrop_List) EndFunc ;==>_copyfiles ; React to items deopped on the GUI Func On_WM_DROPFILES($hWnd, $iMsg, $wParam, $lParam) ; Credit to ProgAndy for DLL calls #forceref $hWnd, $iMsg, $lParam Local $iSize, $pFileName ; Test if the cursor is over the pic control Local $aCInfo = GUIGetCursorInfo($gui010) If Not @error And $aCInfo[4] = $hPic Then ; Get number of files dropped Local $aRet = DllCall('shell32.dll', 'int', 'DragQueryFileW', 'hwnd', $wParam, 'int', 0xFFFFFFFF, 'ptr', 0, 'int', 0) ; Reset array to correct size Global $aDrop_List[$aRet[0] + 1] = [$aRet[0]] ; And add item names For $i = 0 To $aRet[0] - 1 $aRet = DllCall('shell32.dll', 'int', 'DragQueryFileW', 'hwnd', $wParam, 'int', $i, 'ptr', 0, 'int', 0) $iSize = $aRet[0] + 1 $pFileName = DllStructCreate('wchar[' & $iSize & ']') DllCall('shell32.dll', 'int', 'DragQueryFileW', 'hwnd', $wParam, 'int', $i, 'ptr', DllStructGetPtr($pFileName), 'int', $iSize) $aDrop_List[$i + 1] = DllStructGetData($pFileName, 1) $pFileName = 0 Next ; Send the count to trigger the drop function in the main loop GUICtrlSendToDummy($hDrop_Dummy, $aDrop_List[0]) EndIf EndFunc All clear? M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Champak Posted November 27, 2011 Author Share Posted November 27, 2011 lol, hey i didn't write that one, kylomas wrote that as a suggestion. i was just coming back to say i figured out i could pass the path with @GUI_DragFile. But another annoying problem popped up (not with ur version). where it is giving me the same problem originally experienced with the dll version. For whatever reason the drag and drop portion wont work unless at least one file is first opened with the file open dialogue. after that i can do drag and drop to my hearts delight. i'm going to take some time to try and figure this one out before i have you writing me a bunch more scripts . Thanks. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 27, 2011 Moderators Share Posted November 27, 2011 Champak,hey i didn't write that one, kylomas wrote that as a suggestionSorry! But why are you not using the example I posted? It certainly does not need a file opened before it works. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Champak Posted November 27, 2011 Author Share Posted November 27, 2011 OK my hands are up in the air now. Nothing seems to work, and as far as I see there is simply no reason it shouldn't work. Main Problem: drag and drop only works after ANY playlist is processed through the open dialogue option. After that I can drag and drop any playlist and it will work fine (copy files in the playlist to another directory). i've tried to break down where this would be failing, but can't find the fault. I've tried rebuilding the script around this function but that shows me nothing. I've tried the drag and drop in 4 different function styles (dll onevent, while loop, onevent switch, and dummy option), and none of them work. This is everything i'm working with. It just doesnt make sense. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_outfile=InfinitiM35XCreated.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #Include <File.au3> #Include <Array.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <GuiListView.au3> Opt("GUIOnEventMode", 1) ;#cs Global $ASOURCE, $SetPath, $szDrive, $szDir, $szFName, $szExt, $SleepTime, $FileStorage, $PlaylistFolderPath Global $NoFolder = False Global $False = False ; This is the list of files dropped Global $aDrop_List $Image = @TempDir & "\Logo.gif" ;$Image = "C:\Users\Lab\Desktop\M35X\Logo.gif" If Not FileExists($Image) Then FileInstall("\\EEEPCWD2T\part0\Files\My Scripts\Infiniti\Logo.gif", $Image, 1) EndIf $REGLOCATION = "HKEY_CURRENT_USER\SOFTWARE\InfinitiM35X" If RegRead($REGLOCATION, "Location") = "" Then RegWrite($REGLOCATION, "Location", "REG_SZ", "D") EndIf $FileStorage = RegRead($REGLOCATION, "Location") If RegRead($REGLOCATION, "Sleep") = "" Then RegWrite($REGLOCATION, "Sleep", "REG_SZ", "10") EndIf $SleepTime = RegRead($REGLOCATION, "Sleep") $Gui_I = GUICreate("Infiniti M35X", 350, 300, Default, Default, Default, $WS_EX_ACCEPTFILES) GUISetOnEvent($GUI_EVENT_DROPPED, "_DROPPed") GUICtrlCreateLabel("Drive Letter:", 15, 19, 60, 15) $GUI_Location = GUICtrlCreateInput(RegRead($REGLOCATION, "Location"), 80, 17, 20, 20) GUICtrlCreateLabel("Sleep Time:", 15, 47, 60, 15) $GUI_Sleep = GUICtrlCreateInput(RegRead($REGLOCATION, "Sleep"), 80, 44, 30, 20) $GUI_Save = GUICtrlCreateButton("Save", 115, 15, 70, 50);, $BS_ICON) GUICtrlSetOnEvent($GUI_Save, "_Save") $GUI_FindPath = GUICtrlCreateButton("Playlist", 115, 80, 70, 50);, $BS_ICON) GUICtrlSetOnEvent($GUI_FindPath, "_FindFile") $GUI_Image = GUICtrlCreatePic($Image, 15, 135, 174, 93) ;GUICtrlSetState($GUI_Image, $GUI_DROPACCEPTED) $GUI_FilePath = GUICtrlCreateLabel("", 15, 250, 170, 40) GUICtrlSetFont($GUI_FilePath, 9.5, 500) GUICtrlSetBkColor($GUI_FilePath, 0xff0000) $GUI_List = GUICtrlCreateListView("", 190, 2, 155, 240) _GUICtrlListView_SetExtendedListViewStyle($GUI_List, $LVS_EX_CHECKBOXES) ;_GUICtrlListView_SetUnicodeFormat($GUI_List, False) $DirList = _FileListToArray("F:\", "*", 2) If @error Then MsgBox(0,0,@error) _GUICtrlListView_AddColumn($GUI_List, "Playlist", 150) For $I = 1 To UBound($DirList) -1 ;_GUICtrlListView_AddItem($GUI_List, $DirList[$I], 0) GUICtrlCreateListViewItem($DirList[$I], $GUI_List) Next _GUICtrlListView_RegisterSortCallBack($GUI_List) ;_GUICtrlListView_SortItems($GUI_List, 0) _GUICtrlListView_SimpleSort($GUI_List, $False, 0) ; Now create a dummy control to action the "dropped" function $hDrop_Dummy = GUICtrlCreateDummy() GUICtrlSetOnEvent(-1, "_copyfiles") $GUI_Delete = GUICtrlCreateButton("Delete Playlist", 190, 250, 155, 40);, $BS_ICON) GUICtrlSetOnEvent($GUI_Delete, "_Delete") GUISetOnEvent($GUI_EVENT_CLOSE, '_onClose') GUIRegisterMsg(0x233, "On_WM_DROPFILES") GUISetState() While 1 Sleep(100) WEnd Func _copyfiles() _Create($aDrop_List[1]) ;_ArrayDisplay($aDrop_List) EndFunc ;==>_copyfiles ; React to items deopped on the GUI Func On_WM_DROPFILES($hWnd, $iMsg, $wParam, $lParam) ; Credit to ProgAndy for DLL calls #forceref $hWnd, $iMsg, $lParam Local $iSize, $pFileName ; Test if the cursor is over the pic control Local $aCInfo = GUIGetCursorInfo($Gui_I) If Not @error And $aCInfo[4] = $GUI_Image Then ; Get number of files dropped Local $aRet = DllCall('shell32.dll', 'int', 'DragQueryFileW', 'hwnd', $wParam, 'int', 0xFFFFFFFF, 'ptr', 0, 'int', 0) ; Reset array to correct size Global $aDrop_List[$aRet[0] + 1] = [$aRet[0]] ; And add item names For $i = 0 To $aRet[0] - 1 $aRet = DllCall('shell32.dll', 'int', 'DragQueryFileW', 'hwnd', $wParam, 'int', $i, 'ptr', 0, 'int', 0) $iSize = $aRet[0] + 1 $pFileName = DllStructCreate('wchar[' & $iSize & ']') DllCall('shell32.dll', 'int', 'DragQueryFileW', 'hwnd', $wParam, 'int', $i, 'ptr', DllStructGetPtr($pFileName), 'int', $iSize) $aDrop_List[$i + 1] = DllStructGetData($pFileName, 1) $pFileName = 0 Next ; Send the count to trigger the drop function in the main loop GUICtrlSendToDummy($hDrop_Dummy, $aDrop_List[0]) EndIf EndFunc #cs Func _evDroppedFiles(ByRef $dFiles) local $x, $files; For $x = 0 To UBound($dFiles)-1 $files &= $dFiles[$x] & @CRLF Next _Create($files) EndFunc Func On_WM_DROPFILES($hWnd, $Msg, $wParam, $lParam) Local $tDrop, $i, $aRet, $iCount; ;get file count $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "ptr", $wParam, "uint", -1, "ptr", 0, "uint", 0 ) $iCount = $aRet[0] ;get file paths local $aDraggedFiles[$iCount]; For $i = 0 To $iCount-1 $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "ptr", $wParam, "uint", $i, "ptr", 0, "uint", 0) Local $tDrop = DllStructCreate("wchar[" & $aRet[0]+1 & "]") $aRet = DllCall("shell32.dll", "int", "DragQueryFileW", "ptr", $wParam, "uint", $i, "ptr", DllStructGetPtr($tDrop), "uint", $aRet[0]+1) $aDraggedFiles[$i] = DllStructGetData($tDrop, 1); Next ;finalize DllCall("shell32.dll", "int", "DragFinish", "ptr", $wParam) Return _evDroppedFiles($aDraggedFiles); EndFunc #ce Func _DROPPed() Switch @GUI_DropId Case $GUI_Image ; MsgBox(0,0,@GUI_DragFile) _Create(@GUI_DragFile) EndSwitch EndFunc Func _onClose() Exit EndFunc Func _FindFile() $SetPath = RegRead($REGLOCATION, "Location") If $SetPath = "" Then MsgBox(0,"Destination Path Not Set", "Please set a destination path before proceeding.") Else $FindPath = FileOpenDialog("Playlist", "C:\", "All (*.m3u)") If @error = 1 Then MsgBox(0,"Unknown File", "Unable to set file") Else _Create($FindPath) EndIf EndIf EndFunc Func _Delete() For $I = _GUICtrlListView_GetItemCount($GUI_List) To 0 Step -1 If _GUICtrlListView_GetItemChecked($GUI_List, $I) = True Then GUICtrlSetData($GUI_FilePath, "Deleting " & _GUICtrlListView_GetItemText($GUI_List, $I)) DirRemove($FileStorage & ":\" & _GUICtrlListView_GetItemText($GUI_List, $I), 1) _GUICtrlListView_DeleteItem($GUI_List, $I) EndIf Next GUICtrlSetData($GUI_FilePath, "Playlist deleting complete") EndFunc Func _Create($Found) GUICtrlSetData($GUI_FilePath, "Counting files on CF") $DirSize = DirGetSize ($FileStorage & ":\", 1) GUICtrlSetData($GUI_FilePath, "Track Count On CF: " & $DirSize[1]) ;If file coming from drag and drop need to strip CR and LF $Found = StringStripWS($Found, 3) ;Read playlist to array _FileReadToArray($Found, $ASOURCE) If @error Then ConsoleWrite(@CR & @error & @CR) ;_ArrayDisplay($ASOURCE) ;Return _PathSplit($Found, $szDrive, $szDir, $szFName, $szExt) $PlaylistFolder = $szFName $PlaylistFolderPath = $FileStorage & ":\" & $PlaylistFolder $DirPlaylist = DirGetSize ($PlaylistFolderPath, 1) If @error = 1 Then $DirPlaylistCount = 0 ;MsgBox(0,0,"Dir doesn't exist") Else $DirPlaylistCount = $DirPlaylist[1] ;MsgBox(0,0,"Dir does exist") EndIf $FileCount = $ASOURCE[0] + $DirSize[1] - $DirPlaylistCount If $FileCount > 512 Then $ExcededCount = $FileCount - 512 MsgBox(17,"File Count", "You have exceeded the allowed track count by " & $ExcededCount & @CRLF & _ "Delete files from the CF or current playlist.") Return EndIf For $I = $ASOURCE[0] To 0 Step -1 ;Delete blank spaces in array If $ASOURCE[$I] = "" Then _ArrayDelete($ASOURCE, $I) ;Delete entries with "#EXTINFUTF8" which pops up with letters with the squiggly line above them and throws everything off If StringInStr($ASOURCE[$I], "#EXTINFUTF8") Then _ArrayDelete($ASOURCE, $I) Next ;Delete unneded elements in the beginning from array _ArrayDelete($ASOURCE, 0) _ArrayDelete($ASOURCE, 1) ;Delete #EXF entries in array For $I = UBound($ASOURCE) -2 To 0 Step -2 _ArrayDelete($ASOURCE, $I) Next ;_ArrayDisplay($ASOURCE) $var2 = FileExists($PlaylistFolderPath) If $var2 = 0 Then $NoFolder = True ConsoleWrite("!! dir does not exist") EndIf ;Copy files and set modified date time stamp For $I = 0 To UBound($ASOURCE) - 1 ;FileCopy($ASOURCE[$I], $PlaylistFolderPath & "\") FileCopy($ASOURCE[$I], $PlaylistFolderPath & "\", 8) ConsoleWrite($ASOURCE[$I] & @CR) $TestPath = _PathSplit($ASOURCE[$I], $szDrive, $szDir, $szFName, $szExt) GUICtrlSetData($GUI_FilePath, " Progress: " & $I & " of " & UBound($ASOURCE) & @CRLF & " " & $szFName); & $szExt) FileSetTime ( $PlaylistFolderPath & "\" & $szFName & $szExt, "", 1 ) Sleep($SleepTime) Next GUICtrlSetData($GUI_FilePath, " Progress: " & $I & " of " & UBound($ASOURCE) & @CRLF & " Copy Complete") ;Strip path from playlist to compare against tracks in folder $var0 = $szDrive & $szDir $var1 = StringLen($var0) For $I = 0 To UBound($ASOURCE) - 1 $new = StringTrimLeft($ASOURCE[$I], $var1) $ASOURCE[$I] = $new Next ;Read files in playlist folder and strip the path to compare against playlist $FolderArray = _FileListToArray($PlaylistFolderPath, "*.mp3", 1) $var1 = StringLen($PlaylistFolderPath) For $I = 0 To UBound($FolderArray) - 1 StringTrimLeft($FolderArray[$I], $var1) Next _ArrayDelete($FolderArray, 0) ;Delete tracks no longer a part of the playlist from the folder For $J = 1 to UBound($FolderArray) -1 If _ArraySearch ($ASOURCE, $FolderArray[$J]) = -1 Then FileDelete($PlaylistFolderPath & "\" & $FolderArray[$J]) EndIf Next If $NoFolder = True Then GUICtrlCreateListViewItem($PlaylistFolder, $GUI_List) _GUICtrlListView_RegisterSortCallBack($GUI_List) ;_GUICtrlListView_SortItems($GUI_List, 0) _GUICtrlListView_SimpleSort($GUI_List, $False, 0) $NoFolder = False EndIf GUICtrlSetData($GUI_FilePath, " Progress: Process Complete") EndFunc Func _Save() If GUICtrlRead($GUI_Location, 1) <> "" Then RegWrite($REGLOCATION, "Location", "REG_SZ", GUICtrlRead($GUI_Location, 1)) EndIf If GUICtrlRead($GUI_Sleep, 1) <> "" Then RegWrite($REGLOCATION, "Sleep", "REG_SZ", GUICtrlRead($GUI_Sleep, 1)) EndIf EndFunc Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 28, 2011 Moderators Share Posted November 28, 2011 Champak,You need to use just the one function to deal with the drop - in your code you have two: ; Looking for a drop event on the GUI GUISetOnEvent($GUI_EVENT_DROPPED, "_DROPPed") ; Intercepting the WM_DROPFILES message GUIRegisterMsg(0x233, "On_WM_DROPFILES")As you only want the drop to work on the image, I suggest you go with the WM_DROPFILES method I showed you yesterday. I have stripped out a lot of code to leave just the drop code and (hopefully) show you that the drop detection works: expandcollapse popup#include <File.au3> #include <Array.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GuiConstantsEx.au3> #include <GuiListView.au3> Opt("GUIOnEventMode", 1) Global $ASOURCE, $SetPath, $szDrive, $szDir, $szFName, $szExt, $SleepTime, $FileStorage, $PlaylistFolderPath Global $NoFolder = False Global $False = False ; This is the list of files dropped Global $aDrop_List $Image = "M:ProgramAu3 ScriptsImagesFacepalm.jpg" ; ~~~~~~~~~~~~~~~ Need to reset this value for your system $Gui_I = GUICreate("Infiniti M35X", 350, 300, Default, Default, Default, $WS_EX_ACCEPTFILES) ;GUISetOnEvent($GUI_EVENT_DROPPED, "_DROPPed") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< You do not need this GUISetOnEvent($GUI_EVENT_CLOSE, '_onClose') GUICtrlCreateLabel("Drive Letter:", 15, 19, 60, 15) $GUI_Location = GUICtrlCreateInput("Location", 80, 17, 20, 20) GUICtrlCreateLabel("Sleep Time:", 15, 47, 60, 15) $GUI_Sleep = GUICtrlCreateInput("Sleep", 80, 44, 30, 20) $GUI_Save = GUICtrlCreateButton("Save", 115, 15, 70, 50);, $BS_ICON) GUICtrlSetOnEvent($GUI_Save, "_Save") $GUI_FindPath = GUICtrlCreateButton("Playlist", 115, 80, 70, 50);, $BS_ICON) GUICtrlSetOnEvent($GUI_FindPath, "_FindFile") $GUI_Image = GUICtrlCreatePic($Image, 15, 135, 174, 93) ;GUICtrlSetState($GUI_Image, $GUI_DROPACCEPTED) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Nor this $GUI_FilePath = GUICtrlCreateLabel("", 15, 250, 170, 40) GUICtrlSetFont($GUI_FilePath, 9.5, 500) GUICtrlSetBkColor($GUI_FilePath, 0xff0000) $GUI_List = GUICtrlCreateListView("", 190, 2, 155, 240) _GUICtrlListView_SetExtendedListViewStyle($GUI_List, $LVS_EX_CHECKBOXES) $DirList = _FileListToArray("M:MusicMP3", "*", 2) ; ~~~~~~~~~~~~~~~ Need to reset this value for your system If @error Then MsgBox(0, 0, @error) _GUICtrlListView_AddColumn($GUI_List, "Playlist", 150) For $I = 1 To UBound($DirList) - 1 GUICtrlCreateListViewItem($DirList[$I], $GUI_List) Next ; Now create a dummy control to action the "dropped" function $hDrop_Dummy = GUICtrlCreateDummy() GUICtrlSetOnEvent(-1, "_copyfiles") $GUI_Delete = GUICtrlCreateButton("Delete Playlist", 190, 250, 155, 40);, $BS_ICON) GUICtrlSetOnEvent($GUI_Delete, "_Delete") GUISetState() GUIRegisterMsg(0x233, "On_WM_DROPFILES") ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< We do it all with this While 1 Sleep(100) WEnd Func _copyfiles() _Create($aDrop_List[1]) EndFunc ;==>_copyfiles ; React to items deopped on the GUI Func On_WM_DROPFILES($hWnd, $iMsg, $wParam, $lParam) ; Credit to ProgAndy for DLL calls #forceref $hWnd, $iMsg, $lParam Local $iSize, $pFileName ; Test if the cursor is over the pic control Local $aCInfo = GUIGetCursorInfo($Gui_I) If Not @error And $aCInfo[4] = $GUI_Image Then ; Get number of files dropped Local $aRet = DllCall('shell32.dll', 'int', 'DragQueryFileW', 'hwnd', $wParam, 'int', 0xFFFFFFFF, 'ptr', 0, 'int', 0) ; Reset array to correct size Global $aDrop_List[$aRet[0] + 1] = [$aRet[0]] ; And add item names For $I = 0 To $aRet[0] - 1 $aRet = DllCall('shell32.dll', 'int', 'DragQueryFileW', 'hwnd', $wParam, 'int', $I, 'ptr', 0, 'int', 0) $iSize = $aRet[0] + 1 $pFileName = DllStructCreate('wchar[' & $iSize & ']') DllCall('shell32.dll', 'int', 'DragQueryFileW', 'hwnd', $wParam, 'int', $I, 'ptr', DllStructGetPtr($pFileName), 'int', $iSize) $aDrop_List[$I + 1] = DllStructGetData($pFileName, 1) $pFileName = 0 Next ; Send the count to trigger the drop function in the main loop GUICtrlSendToDummy($hDrop_Dummy, $aDrop_List[0]) EndIf EndFunc ;==>On_WM_DROPFILES Func _onClose() Exit EndFunc ;==>_onClose Func _FindFile() EndFunc ;==>_FindFile Func _Delete() EndFunc ;==>_Delete Func _Create($Found) MsgBox(0, "Dropped File", $Found) EndFunc ;==>_Create Func _Save() EndFunc ;==>_SaveWhen I drop a file on the image I get the MsgBox with the full path - do you? If you do get the file passed correctly, then we can start looking at what you do with it in the _Create function - perhaps it is there that you are having problems. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Champak Posted November 28, 2011 Author Share Posted November 28, 2011 sorry, forgot to delete the extra drop function in the last one. yeah the path passes just fine w/ your version. it is failing at the copying point. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 28, 2011 Moderators Share Posted November 28, 2011 Champak,So we look into the function. - 1. First off, I think you need to use _FileListToArray rather than _FileReadToArray - you want a list of files within the dropped folder, not the bytes! ;_FileReadToArray($Found, $ASOURCE) $ASOURCE = _FileListToArray($Found, "*", 1)You had a commented ;_ArrayDisplay($ASOURCE) line in there - had you ever got a sensible return from it? Just adding errorchecking lines is not enough - you need to check the return is what you expect. - 2. Then you will need to add the path to the filename within the FileCopy function - it does not work with just the name. I suggest creating a $sSourcepath variable like this: _PathSplit($Found, $szDrive, $szDir, $szFName, $szExt) $sSourcePath = $szDrive & $szDir & $szFName & ""and then using it like this:FileCopy($sSourcePath & $ASOURCE[$I], $PlaylistFolderPath & "", 8)I cannot test the _ArrayDelete loops as I do not have your file structure, but with the above changes I get all the files within the dropped folder to copy to a new folder without problem. Top Tip: Check what you are using as parameters for a function actually matches what is required and that the return is what you expect to see. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
Champak Posted November 28, 2011 Author Share Posted November 28, 2011 1/ _FileReadToArray is the right function. I need to read the list of files within a m3u playlist, not a list of files from a dir. I'm not dropping a folder, I'm dropping a playlist.The array ALWAYS returns what is expected...that is what is so perplexing...when the files do and don't get copied, it doesn't matter. The arraydisplay function itself in certain instances wont work after a drag and drop (that's another story, i've experienced it before with other scripts and isn't really a concern), but the array is always populated and functions as it should because the printout of files through consolewrite in a loop shows them.2/ The full source path is already within the array copied from the playlist file. So $ASOURCE[$I] is everything needed.All the other functions work fine, it's just that drag and drop doesnt work the first time without using the file dialogue open once. If there was a path, variable, parameter, function, wrong, wouldn't it always fail? Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 28, 2011 Moderators Share Posted November 28, 2011 Champak,_FileReadToArray is the right function. I need to read the list of files within a m3u playlistI see - always difficult trying to debug someone else's code when there is precious to go on in terms of comments. My apologies for having criticised your code. But now I have understood what you were trying to do I can get the code to work every time I drag a playlist onto the image - I have no idea why you cannot. I can drag my self-generated playlists onto the image as often as I want and the files are always copied into the correct location - no need to open the file dialog first. So I am afraid I am going to bow out - sorry I could not find a solution for you. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
kylomas Posted November 28, 2011 Share Posted November 28, 2011 Champak, This may or may not be germain to your issue. When only one file is returned there is no delimiter whereas a list is always delimited. Perhaps your logic does not account for this. 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now