Jump to content
Sign in to follow this  
michaelslamet

[ASK] File Click and Drag

Recommended Posts

michaelslamet

Dear fellow members,

I would like to create a script that allow user to click and drag multiple files into it and then click a button to process those files. It also allow user to delete particular lines from that list.

What I have now is only allow user to click and drag SINGLE FILE hence doesn't allow user to delete particular lines/file list from the list.

Any suggestions (and maybe example) would be very appreciated :)

#cs ----------------------------------------------------------------------------

     ;Original Author: enzo_
     ;Linguagem: AutoIt
     ;Função: Drag and Drop

    #ce ----------------------------------------------------------------------------

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

    $Title = "Func Drag File and Drop"
    $Form1 = GUICreate($Title, 256, 53, -1, -1,-1, $WS_EX_ACCEPTFILES)
    GUISetOnEvent($GUI_EVENT_DROPPED, "Drag")
    WinSetOnTop($Title, "", 1)
    $Input1 = GUICtrlCreateInput("[ ... ]", 8, 24, 241, 21)
    GUICtrlSetState(-1, $GUI_DROPACCEPTED)
    $Label1 = GUICtrlCreateLabel("Click and Drag File here:", 8, 8, 118, 16)
    GUISetState(@SW_SHOW)

    While 1
            $nMsg = GUIGetMsg()
            Switch $nMsg
                    Case $GUI_EVENT_CLOSE
                        Exit
                    Case $Input1
                        Drag()
            EndSwitch
    WEnd

    Func Drag()
     MsgBox(0,0,"ID: "&@GUI_DRAGID & " File: "&@GUI_DRAGFILE &" Drop: "&@GUI_DROPID&@CRLF)
    EndFunc

Share this post


Link to post
Share on other sites
michaelslamet

This code below works great, but how to make the ListView doesn't accept duplicate content? Each row should be unique.

Also, how to allow user to select the row, right click and delete that selected rows?

; original by lazycat
; modded by me

#include <WindowsConstants.au3>
#Include <GUIConstants.au3>
#Include <GuiListView.au3>
;#Include <File.au3>
;#Include <Date.au3>

;Global $WM_DROPFILES = 0x233
Global $gaDropFiles[1]

$Title = "Func Drag File and Drop"
GUICreate($Title, 320, 220, -1, -1, -1, $WS_EX_ACCEPTFILES)
WinSetOnTop($Title, "", 1)
$list = GUICtrlCreateListView('Files', 10, 10, 300, 200)
GUICtrlSendMsg($list, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, -1)
_GUICtrlListView_SetColumnWidth($list, 0, 296)
GUICtrlSetState($list, $GUI_DROPACCEPTED)

GUIRegisterMsg($WM_DROPFILES, 'WM_DROPFILES_FUNC')

GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_DROPPED
            For $i = 0 To UBound($gaDropFiles) - 1
                GUICtrlCreateListViewItem($gaDropFiles[$i], $list)
            Next
    EndSwitch
WEnd

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 $gaDropFiles[$i + 1]
        $gaDropFiles[$i] = DllStructGetData($pFileName, 1)
        $pFileName = 0
    Next
EndFunc

Func quit()
    Exit
EndFunc

Share this post


Link to post
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
Sign in to follow this  

×