Jump to content

Drag and Drop question


Recommended Posts

Hello all,

I was wondering if it's possible to make a gui that lets me drag and drop files/programs in it and open it from there.
Also is this possible with an option to right click and delete an file/program from there?

Haven't wrote any code yet since i have no clue on how to start. So any help and tips are very welcome :)

 

Greetings.

Link to comment
Share on other sites

You could use a listview
Try this to start

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListviewConstants.au3>

GUICreate("listview items", 420, 150, 100, 200, -1, $WS_EX_ACCEPTFILES)
$listview = GUICtrlCreateListView("|column1|column2 ", 10, 10, 400, 130)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 1, 300)

GUICtrlCreateListViewItem("|" & @Autoitexe & "|" & FileGetVersion(@Autoitexe ), $listview)
GUICtrlSetImage(-1, @Autoitexe, -1)   
GUISetState()

While 1
   $msg = GUIGetMsg()
   Switch $msg
       Case $GUI_EVENT_CLOSE 
           Exit
       Case $GUI_EVENT_DROPPED
           GUICtrlCreateListViewItem("|" & @GUI_DragFile & "|" & FileGetVersion(@GUI_DragFile), $listview)
           GUICtrlSetImage(-1, @GUI_DragFile, -1)   
   EndSwitch
Wend

 

Link to comment
Share on other sites

Have a look at this example by Melba23: Link

Edited by MikahS
cleanup

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

M'kay so i've put everything in oneventmode so it's easier for me to code with. So far i've tried a couple of things to make sure i can open the files from the gui without success.

The code i have so far is:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ListviewConstants.au3>

Global $listview, $Main, $test

Opt("GUIOnEventMode", 1)

Main()
Func Main()
$Main = GUICreate("listview items", 420, 150, 100, 200, -1, $WS_EX_ACCEPTFILES)
$listview = GUICtrlCreateListView("|column1 ", 10, 10, 400, 130)

GUICtrlSetState($listview, $GUI_DROPACCEPTED)
GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 1, 365)

GUICtrlCreateListViewItem("|" & @Autoitexe & "|" , $listview)
GUICtrlSetImage(-1, @Autoitexe, -1)
GUISetState()

GUISetOnEvent($GUI_EVENT_CLOSE, "stop")
GUISetOnEvent($GUI_EVENT_DROPPED, "Dropped")
GUISetOnEvent($test, "stop")
EndFunc

Func Dropped()
$test = GUICtrlCreateListViewItem("|" & @GUI_DragFile & "|" , $listview)
        GUICtrlSetImage(-1, @GUI_DragFile, -1)
EndFunc

Func stop()
    MsgBox(0,"",@GUI_DragFile)
    Exit
EndFunc

While 1
    Sleep(50)
WEnd

Never worked with treeview before so sorry if the things i've tried are wrong. But as you see i've tried to make an guisetonevent for $test and the msgbox works it shows me the path of the file i dragged into my gui. altho if i put in multiple files it only shows me the last one i dragged into it. even if i selected the first on i dragged into.

And another thing is it doesn't work if i click on the treeviewitem just if i make an extra button like i used the X button for as a test.

is there another way so i can click the treeviewitem or do i really need to use some sort of a button?

 

Sorry if this wasn't clear i tried my best

Link to comment
Share on other sites

Here is an example of multiple file drag & drop by guinness: link

Otherwise, you are actually working with a ListView control and you'll have to register the WM_NOTIFY event to open something on clicking an item.

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Link to comment
Share on other sites

My pleasure. ^_^

Let us know if you hit any snags. 

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

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