Sign in to follow this  
Followers 0
MattHiggs

(Solved) How does drag and drop work exactly?

3 posts in this topic

#1 ·  Posted (edited)

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
.

Quote

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)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
Local $lvListView = GUICtrlCreateListView("Column 1", 10, 200, 380, 180)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlCreateListViewItem("Some example text", $lvListView)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlCreateListViewItem("More example text", $lvListView)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlCreateListViewItem("Even more example text!", $lvListView)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
FileWrite(@ScriptDir & "\File.txt", "This is some example text")

GUISetState(@SW_SHOW, $hGUI)

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

 

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  
Followers 0