Jump to content
Sign in to follow this  
nacerbaaziz

How to Make AutoIt GUI Accept to Drag Files from Windows Explorer

Recommended Posts

nacerbaaziz

Hello all
I have a question please
I've searched a lot on how to make a GUI for programs designed by Autoit to accepts dragging files from Windows File Explorer
Unfortunately, however, it failed
Is there any way to do this?
Where I am making a audio player and I want to activate the feature of dragging files from Windows Explorer to a program window to play them
I hope to find a simple solution here in this wonderful forum
Thank you very much in advance

Share this post


Link to post
Share on other sites
kylomas

nacerbaaziz,

See the example for GuiCtrlCreateInput in the3 help file...

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
buymeapc

You can start by setting the state of the control you want to drag a file onto, like an input field or similar, with the state of $GUI_DROPACCEPTED and in your main loop, look for $GUI_EVENT_DROPPED. The file path will be held under @GUI_DragFile

The help file has info on this if you get lost.

Cheers!

Share this post


Link to post
Share on other sites
nacerbaaziz

thank you

but it don't work with me

can any one write a example for me

Share this post


Link to post
Share on other sites
SplashFlo

You mean something like this?

 

#include <GuiConstants.au3>
#include <GuiConstantsEx.au3>
#include <FileConstants.au3>
#include <EditConstants.au3>

GuiCreate('Drag and Drop', 700, 600, @DesktopWidth / 2 - 192, _
            @DesktopHeight / 2 - 235, -1, $WS_EX_ACCEPTFILES)

GUICtrlCreateGroup("Dict Files", 5, 5, 570, 90)
GUICtrlCreateLabel('Select file:', 20, 30)
$dropFile = GUICtrlCreateInput ("", 120, 30, 200, 20, -1, $WS_EX_STATICEDGE)
GUICtrlSetState (-1, $GUI_DROPACCEPTED)
GUICtrlSetTip (-1, 'You can drag & drop files here...')


GUICtrlCreateLabel('Select file:', 20, 60)
$dropFile = GUICtrlCreateInput ("", 120, 60, 200, 20, -1, $WS_EX_STATICEDGE)
GUICtrlSetState (-1, $GUI_DROPACCEPTED)
GUICtrlSetTip (-1, 'You can drag & drop files here...')


GuiSetState() ;Loop GUI
While 1
  $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        Exit
  EndSelect
WEnd

 

Share this post


Link to post
Share on other sites
TheSaint

While what SplashFlo provided will work, you will find an Insert can occur rather than Replace for subsequent drops to the same inputs.

So try this instead.

#include <GuiConstants.au3>
#include <GuiConstantsEx.au3>
#include <FileConstants.au3>
#include <EditConstants.au3>

Global $dropFile_1, $dropFile_2

GuiCreate('Drag and Drop', 530, 120, @DesktopWidth / 2 - 192, _
            @DesktopHeight / 2 - 235, -1, $WS_EX_ACCEPTFILES)

GUICtrlCreateGroup("Dict Files", 5, 5, 510, 90)
GUICtrlCreateLabel('File 1:', 20, 30)
$dropFile_1 = GUICtrlCreateInput ("", 80, 30, 400, 20, -1, $WS_EX_STATICEDGE)
GUICtrlSetState (-1, $GUI_DROPACCEPTED)
GUICtrlSetTip (-1, 'You can drag & drop files here...')


GUICtrlCreateLabel('File 2:', 20, 60)
$dropFile_2 = GUICtrlCreateInput ("", 80, 60, 400, 20, -1, $WS_EX_STATICEDGE)
GUICtrlSetState (-1, $GUI_DROPACCEPTED)
GUICtrlSetTip (-1, 'You can drag & drop files here...')


GuiSetState() ;Loop GUI
While 1
  $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        GUIDelete()
        ExitLoop
    Case $msg = $GUI_EVENT_DROPPED
        If @GUI_DropId = $dropFile_1 Then
            GUICtrlSetData($dropFile_1, @GUI_DragFile)
        ElseIf @GUI_DropId = $dropFile_2 Then
            GUICtrlSetData($dropFile_2, @GUI_DragFile)
        EndIf
  EndSelect
WEnd

Exit

 

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
nacerbaaziz

Hello again
Thank you very much for your interaction with my question
I have a simple inquiry
You should link the dragging files with a input controle
I mean, if can I drop the file at anywhere in the window
If possible, please tell me how
thank you very much

Share this post


Link to post
Share on other sites
TheSaint

As far as I know, you cannot just drag & drop to a GUI itself. You need to specify a control to receive the drop.

Try this, which importantly has the $label control created last, is the full size of the GUI, and is set as Transparent.

#include <GuiConstants.au3>
#include <GuiConstantsEx.au3>
#include <FileConstants.au3>
#include <EditConstants.au3>

Global $dropFile_1, $dropFile_2, $label

GuiCreate('Drag and Drop', 530, 120, @DesktopWidth / 2 - 192, _
            @DesktopHeight / 2 - 235, -1, $WS_EX_ACCEPTFILES + $WS_EX_TOPMOST)

GUICtrlCreateGroup("Dict Files", 5, 5, 510, 90)
GUICtrlCreateLabel('File 1:', 20, 30)
$dropFile_1 = GUICtrlCreateInput ("", 80, 30, 400, 20, -1)
GUICtrlSetState($dropFile_1, $GUI_DROPACCEPTED)
GUICtrlSetTip($dropFile_1, 'You can drag & drop files here...')

GUICtrlCreateLabel('File 2:', 20, 60)
$dropFile_2 = GUICtrlCreateInput ("", 80, 60, 400, 20, -1)
GUICtrlSetState($dropFile_2, $GUI_DROPACCEPTED)
GUICtrlSetTip($dropFile_2, 'You can drag & drop files here...')

$label = GUICtrlCreateLabel('', 0, 0, 530, 120)
GUICtrlSetBkColor($label, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetState($label, $GUI_DROPACCEPTED)

GuiSetState() ;Loop GUI
While 1
  $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        GUIDelete()
        ExitLoop
    Case $msg = $GUI_EVENT_DROPPED
        If @GUI_DropId = $dropFile_1 Then
            GUICtrlSetData($dropFile_1, @GUI_DragFile)
        ElseIf @GUI_DropId = $dropFile_2 Then
            GUICtrlSetData($dropFile_2, @GUI_DragFile)
        Else;If @GUI_DropId = $label Then
            MsgBox(262144, "Drop Result", @GUI_DragFile)
        EndIf
  EndSelect
WEnd

Exit

Drag to anywhere but the two Inputs and the MsgBox will popup with file path.

That should give you enough clues to play around with.

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
nacerbaaziz

thank you verry much

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  

  • Similar Content

    • vin1
      By vin1
      i have a script that selects  a text file and deletes a line (text input required) in the text file selected
      i have to make it remove all lines found on a file i name, toRemoveLines.txt
      it has to remove lines from all text files found in a folder
      this is the script that has to be modified
      where it says "select file" it has to be "select folder"
      where it says "line text input" it has to be all lines from a text file
      #Include <File.au3> Global $success = False $file_name = FileOpenDialog("Select file", @ScriptDir, "All files (*.*)", 1+4) $line_text_input = InputBox("Line's text", "Line must contain following text:", "line contains this text") $file_count_lines = _FileCountLines($file_name) for $i = 0 to $file_count_lines $Lines_text_output = FileReadLine($file_name, $i) if StringInStr($Lines_text_output, $line_text_input) then _FileWriteToLine($file_name, $i, "", 1) $success = True ExitLoop EndIf Next if $success = True Then MsgBox(0, "Success", "Line has been deleted") Else MsgBox(0, "Failure", "Line wasn't found") EndIf  
    • nacerbaaziz
      By nacerbaaziz
      Hello
      I have a query please
      It is about windows file explorer
      If i design a tool in autoit language to delete files for example
      and i  added it in the context menu in File Explorer
      If i right-click on any file And you choose the tool, it will be get the path of the selected file or folder
      The problem here is
      If i select a set of files or folders
      it only detect the first one
      The code that i  used is
      if $CMDLine[0] = 0 then
      msgBox(16, "error", "you don't selecte any files")
      exit
      else
      for $i = 1 to $CMDLine[0]
      msgBox(0, "files", $CMDLine[$i]
      next
      endIf
      exit
    • TheSaint
      By TheSaint
      Files Checklist
      Just a simple little (complex enough) program I whipped up, for a purpose ... but only too happy to share.
      It can of course be modified to do more, but at the moment just compares file names with or without path ... Location versus Checklist.
      There are of course other compare programs out there, most doing a lot more than mine (i.e. WinMerge or FileComparer). But I wanted something quick and simple with drag & drop, that uses up a smallish amount of screen real estate.
      NOTE - The SAVE button is also a LOAD one, and displays 'Load' when the list is empty. So you can save and load specific lists. While in SAVE mode, the button can also be used with CTRL held down, to ADD another list to existing (displayed one) ... combining as they say ... though not saved until you SAVE. CLEAR button removes a selected entry, or if used with CTRL held down, queries about removing all listed entries.
              
      Files Checklist v1.2.zip
      Files Checklist v1.3.zip
      Files Checklist v1.4.zip  (Includes a BUGFIX.)
        (source included)
      WARNING - While this program does not act on files or folders ADDED or CHECKED, you might act on the results, so I advise caution, and I also recommend using the new 'Relative' option in v1.3 or newer ... but you still need to understand what you are doing and what the results actually mean. Some basic examples in the next post.
      Enjoy!
      RELATED
      Users might also be interested in another somewhat related program of mine.
      DeleteIf Same
      Cheers!
    • nacerbaaziz
      By nacerbaaziz
      hello dears
      First I would like to apologize to you for my many questions.
      I have a new question if you allow
      I am programming an audio player for blinds
      I had a problem
      I put an option in the folders context menu to Opens the audio files that in the selected folder
      I did not know how to make the Autoit Search the subfolders
      Please provide an example of how to search for  files in the subfolders
      Let's say, for example, MP3 files
      Just give me a simple example and I will try to modify it as appropriate for the program I designing it
      Please help me to find the solution
      Thanks in advance
    • Miliardsto
      By Miliardsto
      Hello.
      Drag option works only on parent window but as we can see on the parent gui is showed up child gui (on the right side with the color).
      Desired action is when we want to drag whole program we can also drag child gui and child gui will drag with parent gui.
      How to do this?
       
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <Array.au3> GUIRegisterMsg($WM_NCHITTEST, "_NCHITTEST") $hGUI = GUICreate("Test", 500, 500, -1, -1) $cButton_0 = GUICtrlCreateButton("Child 0", 10, 10, 80, 30) $cButton_1 = GUICtrlCreateButton("Child 1", 10, 50, 80, 30) $cButton_2 = GUICtrlCreateButton("Child 2", 10, 90, 80, 30) GUISetState(@SW_SHOW, $hGUI) ; guis Global $hChild_[3] Global $countGUI = UBound($hChild_) - 1 ;MsgBox("","",$countGUI) ; licznik dla GUI Global $gui = 0 $hChild_[0] = GUICreate("Child 0", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISetBkColor(0xFF0000) GUISetState(@SW_SHOW, $hChild_[0]) $hChild_[1] = GUICreate("Child 1", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISetBkColor(0x00FF00) GUISetState(@SW_HIDE, $hChild_[1]) $hChild_[2] = GUICreate("Child 2", 350, 300, 150, 0, $WS_POPUP, $WS_EX_MDICHILD, $hGUI) GUISetBkColor(0x0000FF) GUISetState(@SW_HIDE, $hChild_[2]) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cButton_0 _All_Hide() GUISetState(@SW_SHOW, $hChild_[0]) $gui = 0 Case $cButton_1 _All_Hide() GUISetState(@SW_SHOW, $hChild_[1]) $gui = 1 Case $cButton_2 _All_Hide() GUISetState(@SW_SHOW, $hChild_[2]) $gui = 2 EndSwitch WEnd Func _All_Hide() GUISetState(@SW_HIDE, $hChild_[0]) GUISetState(@SW_HIDE, $hChild_[1]) GUISetState(@SW_HIDE, $hChild_[2]) EndFunc Func _NCHITTEST($hWnd, $uMsg, $wParam, $lParam) If $hWnd = $hGUI Then Local $aPos = WinGetPos($hWnd) If Abs(BitAND(BitShift($lParam, 16),0xFFFF)- $aPos[1]) < 500 Then Return $HTCAPTION EndIf Return $GUI_RUNDEFMSG EndFunc  
×