Jump to content

Tracking Multiple Drag n Drops


Recommended Posts

Hello, I need to track multiple drag n drops. When I drop 2 files in my GUI, @GUI_DragFile only returns 1 file :(

Here is the GUI for you work on :):

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 437, 282, 142, -1, BitOR($WS_EX_ACCEPTFILES,$WS_EX_WINDOWEDGE))
$Edit1 = GUICtrlCreateEdit("", 0, 0, 601, 433)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlSetData(-1, "Edit1")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

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

        Case $GUI_EVENT_DROPPED
            MsgBox(48, "Dropped", '@GUI_DragId = ' & @GUI_DragId & @CRLF & '@GUI_DragFile = ' & @GUI_DragFile & @CRLF & '@GUI_DropId = ' & @GUI_DropId)

    EndSwitch
WEnd

; In this case, the edit control populates with dropped files's paths. Please don't use GUICtrlRead to read the file paths, Pretend that the edit ctrl is empty

Thanks in Advance, TD :)

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

Checkout _WinAPI_DragQueryFileEx in the help file.

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Thanks UEZ, But what should I pass for $hDrop? The example does very complex things

Edited by TheDcoder

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

  • Moderators

TheDcoder,

I use the code in this post to deal with multiple drops.

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

The example is using callbacks for getting the drag and drop events. In this case it uses callback for the triggering.

The $hDrop is the $wParam value from the WinProc callback function.

An example using WM messages:

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

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 437, 282, 142, -1, BitOR($WS_EX_ACCEPTFILES,$WS_EX_WINDOWEDGE))
$Edit1 = GUICtrlCreateEdit("", 0, 0, 601, 433)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlSetData(-1, "Edit1")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES")

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

        Case $GUI_EVENT_DROPPED
            MsgBox(48, "Dropped", '@GUI_DragId = ' & @GUI_DragId & @CRLF & '@GUI_DragFile = ' & @GUI_DragFile & @CRLF & '@GUI_DropId = ' & @GUI_DropId)

    EndSwitch
WEnd

Func WM_DROPFILES($hwnd, $msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $lParam
    Local $sFileList = _WinAPI_DragQueryFileEx($wParam)
        If Not @error Then
        For $i = 1 To $sFileList[0]
            ConsoleWrite($sFileList[$i] & @CRLF)
        Next
        _WinAPI_DragFinish($wParam)
        Return 0
    EndIf
    Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_DROPFILES

 

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Because of GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES"). Either GUIGetMsg() or GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES"), not both together.

 

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites


TheDcoder,

Don't short change yourself.  Look at the following simple code...

#include <StaticConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <WinAPISys.au3>
#include <array.au3>

#AutoIt3Wrapper_Add_Constants=n

$hGui010 = GUICreate("", 500, 200, -1, -1, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE))
$lbl010 = GUICtrlCreateLabel("", 10, 10, 480, 180, $SS_SUNKEN)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)

; dummy control to action when files are droppd on $lbl010
$FilesDropped = GUICtrlCreateDummy()

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_DROPFILES, "WM_DROPFILES")

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg

        Case $GUI_EVENT_CLOSE
            Exit
        Case $FilesDropped

            ConsoleWrite('LBL010 has files to process' & @CRLF)
            ;
            ; code to process files in this case just populate an array
            ;
            _arraydisplay(stringsplit(guictrlread($lbl010),@CRLF,3),'Files Dropped on $lbl010')
    EndSwitch

WEnd



Func WM_DROPFILES($hwnd, $msg, $wParam, $lParam)
    Local $sFileList = _WinAPI_DragQueryFileEx($wParam), $str

    If Not @error Then
        For $i = 1 To $sFileList[0]
            $str &= $sFileList[$i] & @CRLF
        Next
        _WinAPI_DragFinish($wParam)
        GUICtrlSetData($lbl010, $str & @CRLF)   ; populate $lbl010
        GUICtrlSendToDummy($FilesDropped)       ; send message to action $FilesDropped

        Return 0
    EndIf

    Return "GUI_RUNDEFMSG"
EndFunc   ;==>WM_DROPFILES

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

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