Sign in to follow this  
Followers 0
satanttin

Drag and Drop question

10 posts in this topic

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.

Share this post


Link to post
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

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

 

Share this post


Link to post
Share on other sites

@Mikell Could be my second choice rather have icons like u have on your desktop. Btw once i added a file with your script i can't open it or remove it.

 

@MikahS Thanks for the link i shall check this out! :)

Share this post


Link to post
Share on other sites

Btw once i added a file with your script i can't open it or remove it.

​Hmm I said "to start" ... unless you want people make the complete script for you ?

Share this post


Link to post
Share on other sites

Think i missed that part. And no i prefer writing everything myself actually.

I will take another look and hope i can do it

Share this post


Link to post
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

Share this post


Link to post
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

 

Share this post


Link to post
Share on other sites

Thanks for the information:) i will check this out^^

Share this post


Link to post
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

 

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