Jump to content
TheDcoder

Tracking Multiple Drag n Drops

Recommended Posts

TheDcoder

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 :)


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites
UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
TheDcoder

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

Edited by TheDcoder

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites
Melba23

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

 

Share this post


Link to post
Share on other sites
UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
TheDcoder

Thanks UEZ :), But why is $DROP_ACCEPTED not executed?


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites
UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
TheDcoder

Thanks :)

 

P.S Now I use a button to select multiple files :P b/c dnd looks complicated


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites
kylomas


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

Share this post


Link to post
Share on other sites
TheDcoder

@kylomas Thanks! :thumbsup:. Now I understanding the purpose of dummy control :)


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

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

×