Sign in to follow this  
Followers 0
Ascend4nt

File(s) Drag & Drop

9 posts in this topic

#1 ·  Posted (edited)

Send "Drag & Drop File(s)" Message

I was looking for this functionality before, and couldn't figure out the correct method for using the WM_DROPFILES message. Thankfully today I came across the thread ' and found working, but flawed, code for doing exactly this. Specifically, (his 'DoDragDrop' function).

I cleaned up the code, added error checking, Unicode & x64 support, and fixed the Global memory management issues. The result is down below.

Also, see ProgAndy's COM implementation of Drag&Drop: '

Another good reference, besides those in the thread above, is this article at CodeProject: 'How to Implement Drag and Drop Between Your Program and Explorer'

Examples of usage:

TeraCopy

_FileDragDrop(WinGetHandle("[REGEXPTITLE:TeraCopy.*]"),@ScriptFullPath&'|'&@AutoItExe)

Notepad++:

$hNPPlus=WinGetHandle("[CLASS:Notepad++]")
$aNPPPos=WinGetPos($hNPPlus)
;~ WinActivate($hNotePad)
$sProgramFiles=@ProgramFilesDir
If @AutoItX64 Then $sProgramFiles&=' (x86)'
$iRet=_FileDragDrop($hNPPlus,@ScriptFullPath&'|'&$sProgramFiles&"\AutoIt3\Include\Memory.au3",$aNPPPos[2]/2,$aNPPPos[3]/2)
ConsoleWrite("Return: "&$iRet&" @error="&@error&", @extended="&@extended&@CRLF)

Be sure to credit the original authors, or leave the headers intact, if you use the code :graduated:

*edit: for some friggin reason I can't post the code in the post - I get a 'You must enter a post' error message - wtf. Attaching it for now..

UPDATES:

2010-12-4 (yup, today!):

  • Fixed ANSI implementation
  • Changed Memory allocation type to 'Fixed' (thanks trancexx)
  • Added X, Y position parameters - actually needed for some programs (Notepad++ for example)

_FileDragDrop.au3

Edited by Ascend4nt

Share this post


Link to post
Share on other sites



Both ways, KaFu. Maybe there's some formatting in the script that the forum doesn't recognize? *shrug*

Share this post


Link to post
Share on other sites

Share this post


Link to post
Share on other sites

Thanks. As far as I can recall, TeraCopy was the only program I needed this for a while back. I think there were other types of Drag-and-Drop messages I wanted to use also, but can't recall for what.

Oh, and for anyone that is curious - no, this doesn't seem to work for Explorer windows, but then that's more of a job for FileCopy().

Share this post


Link to post
Share on other sites

It's nice.

Btw, is there any particular reason for allocating movable memory?

Fixed memory would result in shorter (safer) code.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

trancexx,

For some odd reason I thought it needed a handle to a Global Memory object, but after some tests, it seems it works fine with a pointer instead. Thanks for the help. Updated the post with the new changes, plus ANSI fixes.

UPDATES:

2010-12-4:

  • Fixed ANSI implementation
  • Changed Memory allocation type to 'Fixed' (thanks trancexx)
  • Added X, Y position parameters - actually needed for some programs (Notepad++ for example)
[*edit: added X,Y..] Edited by Ascend4nt

Share this post


Link to post
Share on other sites

#9 ·  Posted

I'm sorry but I need to push this thread ..
The UDF works fine on most of the programs. But I'm having a hard time getting it to work with Internet Explorer. There are certain websites which accept files to be dragged and dropped into them. For example http://www.mapshaper.org/
I want to add a file using this UDF but I just can't get it to work .. I tried with and without coordinates etc. but still no luck. Googling and using the search function won't help me either ..

Do you guys know how to get this to run? :)

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

  • Similar Content

    • Rapidnxit
      [solved] send multiple files by email from a file list
      By Rapidnxit
      Hi! I want to send by mail some files with a certain extension (.xml in my case). These files are located in the script folder. First, I thought to use _FileListToArrayRec function to have a list of these files. But than I don't know how to send them all at once. I know that I can attach multiple files in this way: path1;path2;path3; etc.  and so I have tried to make a string of this type with the path of the files (with a for loop) but It doesn't attach any file (only instructions.txt). How could I do? ( what I did is just an idea, if there's something better that would be great) Thanks!
      $aArrayXml = _FileListToArrayRec(@ScriptDir, "*.xml", $FLTAR_FILES) _ArrayDisplay($aArrayXml, "LIST XML") $LenghtArrayXml = UBound($aArrayXml) If ($LenghtArrayXml > 2) Then For $i = 2 To $LenghtArrayXml - 1 $temp = "&@ScriptDir&""\"&$aArrayXml[$i]&";"&"""" $XmlListFile = $XmlListFile & $temp Next EndIf $XmlListFile = StringTrimLeft($XmlListFile, 1) if($LenghtArrayXml = 2)Then $rc =_INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, @ScriptDir&"\"&$aArrayXml[1]&";"&@ScriptDir&"\instructions.txt", $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl) Else $rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, @ScriptDir&"\"&$aArrayXml[1]&$XmlListFile&@ScriptDir&"\instructions.txt", $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl) EndIf  
    • FrankSchneidewind
      [GUI] Drag&Drop files -> Get filename
      By FrankSchneidewind
      Hi all,
      I got a quick question regarding Drag&Drop with GUIs. I made a little script that does something with files and I need a way to get the name/path of the file when I drag&drop it into the GUI. Is there a quick way to do this?

      Tyvm in advance!
      Neo
    • Jdr
      More reliable check for file
      By Jdr
      I'm trying to check for the existance of a file, on logon the file is there, then gets deleted and after a while recreated. I'm using this code:
      Sleep(100) If not FileExists($sFile) Then Sleep(150) If FileExists($sFile) Then GUICtrlSendToDummy($iDummy) What happens is this: 
      User logs on, the file is present, or at least it usually is After about 10 seconds the file gets deleted Then after about 50 seconds the file gets created again, this is when I need the check, because now the process is finished. The above code is part of a pretty long do....until false loop running an animation.
      The problem is that sometimes this code fails. Without the sleep statements it didn't work at all so I think this is a timing issue. Pretty primitive code I admit, there must be a better way...
       
    • cherrylatte
      running files in order
      By cherrylatte
      hi
      I'm trying to execute files 
      I want it to run in order.
      for instance, if there's folder like below, I want to run 1.exe > 2.exe > 3.exe
      root folder
        |___folder 1 > 1.exe
        |___folder2 > 2.exe
        |___folder3 > 3.exe
       
      What I did to do the above, was to make a text file that contains the path to each of those files and put those in array form.
      but copying and pasting every path of those files into a text file is very exhausting thing to do when there's like hundreds of files to execute.
      So I was wondering if there is a simple way to run those files.
      I'd be thankful if anybody answers it.