Jump to content

Drag'n'drop from Windows Explorer to Application for windows 10


mdd
 Share

Recommended Posts

3 minutes ago, mdd said:

Please  share the code for Drag'n'drop from Windows Explorer to Application for windows 10

Which code? But, mostly, which application? :D
Need more information about what you're attempting to do :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

Here's a old script, a MP3 player with this feature. The included bilderdaten.au3 is to big for upload. I'm sure you can get it runing without to see the result. The func's WM_DROPFILES_FUNC, _FilesDropped and lines

Global $idfrmChild = GUICreate($sProgTitel & $sProgVer, $iWidht, $iHeight - 35, 1, 35, $WS_POPUP, BitOR($WS_EX_MDICHILD, $WS_EX_ACCEPTFILES), $idfrmMain)
...
...
GUISetOnEvent($GUI_EVENT_DROPPED, "_FilesDropped")

are the most important for your own project.

Wiped my script:

  • #include <StaticConstants.au3>
    #include <WindowsConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <ButtonConstants.au3>
    #include <GuiListView.au3>
    ;#include <array.au3>
    #include <File.au3>
    #include <Misc.au3>
    #include <EditConstants.au3>
    #include <String.au3>
    
    Opt("GUIOnEventMode", 1) ;ONEvent Mode.
    Opt("MustDeclareVars", 1)
    
    Global $sLiz = "Settings.Dat", $sLVdat = "Files"
    Global $iWidht = 600, $iHeight = 600, $hListView
    Global $idContextmenu, $idInsertitem, $idRenameitem, $idDeletemenu, $idDeleteAll, $idDeleteitem
    Global $aDropFiles[1]
    Global $sProgTitel = "Drag&Drop files to LV DEMO ", $sProgVer = "0.8.5.8"
    
    Global $out
    ;#cs
    If _Singleton($sProgTitel & $sProgVer, 1) = 0 Then
        ;   MsgBox(64, $sProgTitel & $sProgVer, $sProgTitel & $sProgVer & ' ist bereits gestartet',5)
        WinActivate($sProgTitel & $sProgVer)
        If _Singleton($sProgTitel & "Einstellungen", 1) Then
            WinActivate($sProgTitel & "Einstellungen")
        EndIf
        Exit
    EndIf
    ;#ce
    
    Global $hGUI = GUICreate($sProgTitel & $sProgVer, $iWidht, $iHeight - 35, 1, 35, Default, $WS_EX_ACCEPTFILES)
    GUISetOnEvent($GUI_EVENT_DROPPED, "_FilesDropped")
    GUISetOnEvent($GUI_EVENT_CLOSE, "_ExitMain")
    
    Local $idLV_Player = GUICtrlCreateListView("Name: |Beschreibung |Pfad", 5, 5, $iWidht - 10, $iHeight - 45, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT))
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
    GUICtrlSetFont(-1, 9, 800)
    GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
    
    _LoadLVs()
    
    _GUICtrlListView_SetColumnWidth($idLV_Player, 0, $LVSCW_AUTOSIZE)
    _GUICtrlListView_SetColumnWidth($idLV_Player, 1, 0) ;zweite Spalte versteckt wird derzeit nicht benutzt
    _GUICtrlListView_SetColumnWidth($idLV_Player, 2, $LVSCW_AUTOSIZE) ;dritte Spalte versteckt
    
    $idContextmenu = GUICtrlCreateContextMenu($idLV_Player)
    $idDeletemenu = GUICtrlCreateMenu("Löschen...", $idContextmenu)
    $idDeleteAll = GUICtrlCreateMenuItem("Alle Einträge", $idDeletemenu)
    GUICtrlSetOnEvent(-1, '_DeleteAll')
    $idDeleteitem = GUICtrlCreateMenuItem("ausgewählte Einträge", $idDeletemenu)
    GUICtrlSetOnEvent(-1, '_DeleteItem')
    GUICtrlCreateMenuItem("", $idContextmenu)
    _Config()
    GUISetState()
    
    GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES_FUNC")
    
    While 1
        Sleep(1000)
    WEnd
    
    #Region ;funcs für Fensterhandling
    Func _Config()
        Local $aPos[4], $i, $j
        $aPos[0] = IniRead($sLiz, "Pos", "x", "20")
        $aPos[1] = IniRead($sLiz, "Pos", "y", "20")
        WinMove($hGUI, '', $aPos[0], $aPos[1])
    EndFunc   ;==>_Config
    
    Func _SaveConfig()
        Local $i, $aPos = WinGetPos($hGUI)
        IniWrite($sLiz, "Pos", "x", $aPos[0])
        IniWrite($sLiz, "Pos", "y", $aPos[1])
        IniWrite($sLiz, "Pos", "width", $aPos[2])
        IniWrite($sLiz, "Pos", "height", $aPos[3])
        For $i = 0 To _GUICtrlListView_GetColumnCount($idLV_Player) - 1
            IniWrite($sLiz, "Player", "Col[" & $i & "]", _GUICtrlListView_GetColumnWidth($idLV_Player, $i))
        Next
    EndFunc   ;==>_SaveConfig
    
    Func _exitMain()
        _saveLVs()
        _SaveConfig()
        Exit
    EndFunc   ;==>_exitMain
    
    Func _Minimize()
        GUISetState(@SW_MINIMIZE, $hGUI)
    EndFunc   ;==>_Minimize
    
    Func _DeleteAll()
        _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($idLV_Player))
    EndFunc   ;==>_DeleteAll
    
    Func _Deleteitem()
        _GUICtrlListView_DeleteItemsSelected(GUICtrlGetHandle($idLV_Player))
    EndFunc   ;==>_Deleteitem
    #EndRegion ;funcs für Fensterhandling
    
    Func _saveLVs()
        Local $sFile, $aItem, $hFileOut
        $hFileOut = FileOpen($sLVdat, 2)
        For $j = 0 To _GUICtrlListView_GetItemCount($idLV_Player) - 1
            $aItem = _GUICtrlListView_GetItemTextString($idLV_Player, $j)
            FileWriteLine($hFileOut, $aItem)
        Next
        FileClose($hFileOut)
    EndFunc   ;==>_saveLVs
    
    Func _LoadLVs()
        Local $aItems
        If FileExists($sLVdat) Then
            $aItems = ""
            _FileReadToArray($sLVdat, $aItems)
            If IsArray($aItems) Then
                _GUICtrlListView_DeleteAllItems($idLV_Player)
                ;;;_ArrayDisplay($aItems)
                For $j = 1 To $aItems[0]
                    GUICtrlCreateListViewItem($aItems[$j], $idLV_Player)
                Next
            EndIf
        EndIf
    EndFunc   ;==>_LoadLVs
    
    
    #Region ;Drag and Drop
    Func WM_DROPFILES_FUNC($hWnd, $msgID, $wParam, $lParam)
        Local $nSize, $pFileName
        Local $nAmt = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", 0xFFFFFFFF, "ptr", 0, "int", 255)
        For $i = 0 To $nAmt[0] - 1
            $nSize = DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", 0, "int", 0)
            $nSize = $nSize[0] + 1
            $pFileName = DllStructCreate("char[" & $nSize & "]")
            DllCall("shell32.dll", "int", "DragQueryFile", "hwnd", $wParam, "int", $i, "ptr", DllStructGetPtr($pFileName), "int", $nSize)
            ReDim $aDropFiles[$i + 1]
            $aDropFiles[$i] = DllStructGetData($pFileName, 1)
            $pFileName = 0
        Next
    EndFunc   ;==>WM_DROPFILES_FUNC
    
    Func _FilesDropped()
        Local $szDrive, $szDir, $szFName, $szExt, $split
        _GUICtrlListView_BeginUpdate($idLV_Player)
        For $i = 0 To UBound($aDropFiles) - 1
            $split = _PathSplit($aDropFiles[$i], $szDrive, $szDir, $szFName, $szExt)
            $szExt = StringUpper($szExt)
            ;;consolewrite($aDropFiles[$i] & ", " & $szExt & @CRLF)
            Switch $szExt
                ;Case ".MP3", ".MPEG", ".MPG", ".WAV" ;
                Case ".MP3", ".WMV", ".WAV"
                    ;bei MPEG gehen Fenster mit Video auf werden aber nciht wieder geschlossen
                    ;wenn das gerade laufende Video geschlossen wird hängt sich Programm auf
                    ;daher keine MPEG MPG
                    GUICtrlCreateListViewItem($szFName & "||" & $aDropFiles[$i], $idLV_Player)
            EndSwitch
        Next
        _GUICtrlListView_SetColumnWidth($idLV_Player, 0, $LVSCW_AUTOSIZE)
        _GUICtrlListView_EndUpdate($idLV_Player)
    EndFunc   ;==>_FilesDropped
    #EndRegion ;Drag and Drop

Only MP3, WMV, MPG and WAV Files are allowed in this demo, other files are ignored.

 

 

Edited by AutoBert
Link to comment
Share on other sites

18 hours ago, FrancescoDiMuro said:

Which code? But, mostly, which application? :D
Need more information about what you're attempting to do :)

is it possible to drag and drop the folder from explorer into image application using autoit automation tool? The folder contains .arw or .arq files

if yes, please share some inputs for the same

Edited by mdd
Link to comment
Share on other sites

@mdd

Your request is not clear enough.

Do you want to drag and drop ANY folder from Windows Explorer to ANY application?

Is this application created by you?

Then, if those files are images, you want to display them after the drag and drop finished?

Give us as much information as you can.

Post some code if you have.

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

40 minutes ago, FrancescoDiMuro said:

if those files are images, you want to display them after the drag and drop finished?

@FrancescoDiMuro

yes, it should display the images(.arw/ arq images) after drag and drop is finished into the application

Edited by mdd
Link to comment
Share on other sites

  • Moderators

mdd,

I dislike people demanding by name that I respond to their threads - just as I do not appreciate being PMed about the same matter. Please do neither again.

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

@mdd

So, you have a list of files ( pictures ) in a folder, and you would like to drag and drop them in another application.

If this is what you're trying to do, the first thing you should do is get the list of files with _FileListToArray() or _FileListToArrayRec().

Then, you could think to copy these files to the clipboard, and pasting them in your application... Did you already try that manually? :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

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...