Jump to content

Drag & Drop Help


 Share

Recommended Posts

Hello all. Writing an app and have an edit box which is accepting the drop but can't get it to open or read a file. Works of course when reading file from open dialog but not in this case. What I'm trying to accomplish is if a user drops a file into the Edit box then it will open that file and run my function. Any suggestions? Below is the code I have currently from searching the forums and finding posts from Melba23. This is just the important code for testing. Rest of my app is working fine.

$Form1_1 = GUICreate("My Program", 498, 354, -1, -1, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE))
$Edit1 = GUICtrlCreateEdit("", 0, 32, 497, 281)

GUICtrlSetState($Edit1, $GUI_DROPACCEPTED)

While 1

    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_DROPPED
            $File = @GUI_DragFile
            Switch @GUI_DropId
                Case $Edit1
                    FileRead($File)
                    If @error Then
                        MsgBox(0, "Error", "Not open")
                    EndIf
            EndSwitch
        EndSwitch
WEnd
Link to comment
Share on other sites

Unfortuneately @GUI_DropId can be a list of files separated by @CRLF. So

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
; *** End added by AutoIt3Wrapper ***
#AutoIt3Wrapper_Add_Constants=n
;$tt = FileRead("C:\Documents and Settings\Martin\My Documents\baks\spacerSaw\saw_21Apr2008\bcc.txt")
;ConsoleWrite($tt & @CRLF)

$Form1_1 = GUICreate("My Program", 498, 354, -1, -1, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE))
$Edit1 = GUICtrlCreateEdit("", 0, 32, 497, 281)
$File = ''
GUICtrlSetState($Edit1, $GUI_DROPACCEPTED)
GUISetState()
While 1

    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $GUI_EVENT_DROPPED
    $File = stringsplit(@GUI_DragFile,@CRLF,2)
            Switch @GUI_DropId
    Case $Edit1
    $tt = FileRead($File[0])
    If @error Then
    MsgBox(0, "Error", "Not open")
                    Else
                        ;ConsoleWrite($tt & @CRLF);just to test
    EndIf
    EndSwitch

    EndSwitch



WEnd
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Unfortuneately @GUI_DropId can be a list of files separated by @CRLF. So

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
; *** End added by AutoIt3Wrapper ***
#AutoIt3Wrapper_Add_Constants=n
;$tt = FileRead("C:\Documents and Settings\Martin\My Documents\baks\spacerSaw\saw_21Apr2008\bcc.txt")
;ConsoleWrite($tt & @CRLF)

$Form1_1 = GUICreate("My Program", 498, 354, -1, -1, -1, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE))
$Edit1 = GUICtrlCreateEdit("", 0, 32, 497, 281)
$File = ''
GUICtrlSetState($Edit1, $GUI_DROPACCEPTED)
GUISetState()
While 1

    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $GUI_EVENT_DROPPED
    $File = stringsplit(@GUI_DragFile,@CRLF,2)
            Switch @GUI_DropId
    Case $Edit1
    $tt = FileRead($File[0])
    If @error Then
    MsgBox(0, "Error", "Not open")
                    Else
                        ;ConsoleWrite($tt & @CRLF);just to test
    EndIf
    EndSwitch

    EndSwitch



WEnd

Ahhhh! That explains it. That's something I would have never figured out. How would one determine something like that so I know for future references? Thank you so much! Just tested and it reads. Now just gotta figure out how to incorporate it in my code. But gave me something to work with.
Link to comment
Share on other sites

.. How would one determine something like that so I know for future references?

I know that you can drop a selection of files though I couldn't remember what the separator was. I did

ConsoleWrite(STringLen($GUI_DragFile) @CRLF)

and saw that it was 2 characters more than the path length, so I guessed the separarator was @CRLF and it was appended even if only one file was dropped. It was probably something I should have known, or did know once, but I know now for another few weeks anyway.

The help file could be more helpful in it's information about @GUI_DragFile I think.

EDIT:I had used $GUI_DropId but meant $GUI_DragFile.

Edited by martin
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...