Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

File(s) Drag & Drop

File Drag Drop WM_DROPFILES

  • Please log in to reply
7 replies to this topic

#1 Ascend4nt

Ascend4nt

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,371 posts

Posted 05 December 2010 - 01:09 AM

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 'Drag and Drop - the other way around', and found working, but flawed, code for doing exactly this. Specifically, post #60 by Martin (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: 'Drag and Drop with Explorer'.

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)

Attached Files


Edited by Ascend4nt, 14 September 2011 - 02:41 AM.








#2 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,409 posts

Posted 05 December 2010 - 01:13 AM

On quick and full editor? Was already curious and wondering :graduated:...

#3 Ascend4nt

Ascend4nt

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,371 posts

Posted 05 December 2010 - 01:17 AM

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

#4 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,409 posts

Posted 05 December 2010 - 01:25 AM

Nice, that one goes straight to the snippet box, offers a good new way to automate applications :graduated:... Thanks m8!

#5 Ascend4nt

Ascend4nt

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,371 posts

Posted 05 December 2010 - 01:36 AM

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().

#6 trancexx

trancexx

    Queen F. Elizabeth MCXI

  • Active Members
  • PipPipPipPipPipPip
  • 6,246 posts

Posted 05 December 2010 - 01:54 AM

It's nice.

Btw, is there any particular reason for allocating movable memory?
Fixed memory would result in shorter (safer) code.
...... ......
.:oOOOOo:. .:oOOOOo:.
.:oOO:'':Oo:. .:oO:'':OOo:.
.:oO: 'Oo:oO' :Oo:.
:oO: 'o'
:Oo:
:oO: :Oo:
':oO: OT9AO0IEDrk :Oo:'
':oO: :Oo:'
':oO. .Oo:'
':oO
. .Oo:'
':oO. .Oo:'
':oO. .Oo:'
'oO:Oo'
'o' :kiss:





.
eMyvnE


#7 Ascend4nt

Ascend4nt

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,371 posts

Posted 05 December 2010 - 02:46 AM

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, 05 December 2010 - 03:45 AM.


#8 KaFu

KaFu

    Hey, it's just me, KhaFoo...

  • MVPs
  • 3,409 posts

Posted 05 December 2010 - 10:01 AM

Update downloaded :graduated:. For Explorer windows copy/move operations I use this example by ProgAndy via clipboard...





Also tagged with one or more of these keywords: File, Drag, Drop, WM_DROPFILES

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users