Jump to content
Sign in to follow this  

(Solved) How does drag and drop work exactly?

Recommended Posts


There is surprisingly little said about it in the help file, other than when it is mentioned as a style and the fact that the GUI containing the Edit/Input needs to have a particular extended style.  One thing I would like to know in order to make things "click": what are the @GUI_Drag ID and @GUI_DropID macros refer to.  I assume that, along with @GUI_DragFile, these three macros are the key to getting this process to work.  Can someone please provide me with some info or correct me if I'm wrong?

Edited by MattHiggs

Share this post

Link to post
Share on other sites

Under the GUICtrlSetStyle is the information you want


If $GUI_DROPACCEPTED (8) is set to a visible control a drag & drop can be taken in account. The edit/input control will be set with the filename.
For other controls on reception of $GUI_EVENT_DROPPED, @GUI_DragId will return the controlID from where the drag start (-1 if from a file, @GUI_DragFile contain the filename being dropped) and @GUI_DropId returns the controlID of the dropped control.
Only dragging a ListviewItem will start the drag & drop process. The @GUI_DragId will be the ListView controlID.

And an example to use it

#include <GUIConstants.au3>

Global $hGUI = GUICreate("Drag and Drop", 400, 400, -1, -1, -1, $WS_EX_ACCEPTFILES)
Local $edtDrop = GUICtrlCreateEdit("", 10, 10, 380, 180)
Local $lvListView = GUICtrlCreateListView("Column 1", 10, 200, 380, 180)
GUICtrlCreateListViewItem("Some example text", $lvListView)
GUICtrlCreateListViewItem("More example text", $lvListView)
GUICtrlCreateListViewItem("Even more example text!", $lvListView)
FileWrite(@ScriptDir & "\File.txt", "This is some example text")

GUISetState(@SW_SHOW, $hGUI)

While (True)
    Switch (GUIGetMsg())
        Case $GUI_EVENT_CLOSE
            FileDelete(@ScriptDir & "\File.txt")
            Exit 0
            If (@GUI_DragId = -1) Then
                ConsoleWrite("Dragging from a file" & @CRLF)
                GUICtrlSetData(@GUI_DropId, FileRead(@GUI_DragFile))
                ConsoleWrite("Dragging from a Listview item"& @CRLF)
                GUICtrlSetData(@GUI_DropId, StringTrimRight(GUICtrlRead(GUICtrlRead(@GUI_DragId)), 1))
            ConsoleWrite(@GUI_DragId & " | " & @GUI_DropId & " | " & @GUI_DragFile & @CRLF)


Share this post

Link to post
Share on other sites

Ah.  Now I see it.  Sorry about that.  The help file can be a bit hard to follow at times in terms of finding where information is stored.

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