Sign in to follow this  
Followers 0
DanielDaniel

Drag Drop to Ion

4 posts in this topic

Hi all,

I am fairly new to AutoIt, so forgive this question if it is basic...

I want to have a Window with an icon on it. If the user drags a file onto this icon then I want AutoIt to receive the path to this file and perform an action based on it. So, anyone know how I can create an icon control that will accept a drag/drop action and then read the filepath from the item dropped onto it?

Cheers,

Daniel

Share this post


Link to post
Share on other sites



DanielDaniel,

Welcome to the AutoIt forum. :graduated:

What you want to do is not too hard to code. You just have to set the correct states for the GUI and the control and then use the Drag/Drop macros kindly provided by the Devs. Look for the <<<<<<<<<< lines: :(

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

Opt("GUIOnEventMode", 1)

GUICreate('Drop file onto icon', 300, 300, -1, -1, -1, $WS_EX_ACCEPTFILES) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUISetOnEvent($GUI_EVENT_CLOSE, 'Quit')

$hIcon = GUICtrlCreateIcon("C:\Program Files\AutoIt3\Icons\filetype-blank.ico", -1, 10, 10, 40, 40)
GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

GUISetOnEvent($GUI_EVENT_DROPPED, 'DropFile')
GUISetState()

While 1
    Sleep(100)
WEnd

Func DropFile()
    If @GUI_DropId = $hIcon Then MsgBox(0, "File Title", @GUI_DragFile) ; <<<<<<<<<<<<<<<<<<<<<<<
EndFunc   ;==>DropFile

Func Quit()
    Exit
EndFunc   ;==>Quit

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

DanielDaniel,

Welcome to the AutoIt forum. :graduated:

What you want to do is not too hard to code. You just have to set the correct states for the GUI and the control and then use the Drag/Drop macros kindly provided by the Devs. Look for the <<<<<<<<<< lines: :(

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

Opt("GUIOnEventMode", 1)

GUICreate('Drop file onto icon', 300, 300, -1, -1, -1, $WS_EX_ACCEPTFILES) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
GUISetOnEvent($GUI_EVENT_CLOSE, 'Quit')

$hIcon = GUICtrlCreateIcon("C:\Program Files\AutoIt3\Icons\filetype-blank.ico", -1, 10, 10, 40, 40)
GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

GUISetOnEvent($GUI_EVENT_DROPPED, 'DropFile')
GUISetState()

While 1
    Sleep(100)
WEnd

Func DropFile()
    If @GUI_DropId = $hIcon Then MsgBox(0, "File Title", @GUI_DragFile) ; <<<<<<<<<<<<<<<<<<<<<<<
EndFunc   ;==>DropFile

Func Quit()
    Exit
EndFunc   ;==>Quit

M23

Wow!!!! Thanks a million! :-):-):-)

Share this post


Link to post
Share on other sites

DanielDaniel,

My pleasure. :graduated:

When you reply in future please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. :(

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

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