Sign in to follow this  
Followers 0
Ascend4nt

File(s) Drag & Drop

8 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

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

    • Scottswan
      Copy folder and file names and write them to a text file
      By Scottswan
      Basically I'm looking to make a snapshot of a whole HD's folders and files in one text file. Just the names. Preferably in alphabetical order.
      Folder 1
          File 1
          File 2
          File 3
      Folder 2
         Etc

      Is there a function that can copy just the names without opening the files? An alternative would be to put each into rename mode and then copy the text, but that is going to be painfully slow.
      Thanks.
    • 9252Survive
      Help with OutlookEX - Sending Email/ Monitoring File
      By 9252Survive
      Hello, 
      I am trying to use the latest version of OutlookEx.au3 and my script is able to send the email to the user first time but second time I am getting this error (see attached) I am trying to check a file every min and verify if the file has been modified, if the file was not modified then an email is sent. It works for the first time but fails in the second iteration. Also, attaching my code, I am very new to AutoIT, any help would be much appreciated! 

      Thanks! 
       
       
      #AutoIt3Wrapper_AU3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #AutoIt3Wrapper_AU3Check_Stop_OnWarning=Y #include <MsgBoxConstants.au3> #include <Debug.au3> #include <File.au3> #include <WinAPI.au3> #include <GuiComboBox.au3> #include <Date.au3> #include <AutoItConstants.au3> #include <Array.au3> #include <Process.au3> #include <StringConstants.au3> #include <FileConstants.au3> ; include for file functions #include <WinAPIFiles.au3> #include <_SingleScript.au3> #include <WinNet.au3> #include <Timers.au3> #include <INet.au3> #include <OutlookEX.au3> #include <DateCalc.au3> #Region AutoIT_Options Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=No case Opt("WinSearchChildren", 1) ;0=no, 1=search children also Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info Opt("TrayAutoPause", 0) ; 0 = no pause , 1 = pause when tray icon is clicked #EndRegion AutoIT_Options Global $logFileName = "Test" & "-" & @YEAR &"_"&@MON& "." & "log" Global $logfile = @ScriptDir &"\"& $logFileName Global $LastModTime Global $LastModTime Global $LastModTimeStamp Global $FiletoCheck_1 Global $FiletoCheck_2 Global $oOutlook = _OL_Open() Func _SendAlert() If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF", "Error creating a connection to Outlook. @error = " & @error & ", @extended = " & @extended) ;Global $sCurrentUser = $oOutlook.GetNameSpace("MAPI").CurrentUser.Name ;_OL_Wrapper_SendMail($oOutlook, $sCurrentUser, "", "", "Travel Time Calc Engine ALERT! ", "An error has occurred, the log file has not changed since: " & $LastModTimeStamp, "", $olFormatHTML, $olImportanceHigh _OL_Wrapper_SendMail($oOutlook, "testemail@gmail.com", "", "", "ALERT! ", "An error has occurred, the log file has not changed since: " & $LastModTimeStamp, "", $olFormatHTML, $olImportanceHigh) If @error <> 0 Then Exit MsgBox(16, "OutlookEX UDF: _OutlookSendMail Wrapper Script", "Error sending mail. @error = " & @error & ", @extended: " & @extended) ;MsgBox(64, "OutlookEX UDF: _OutlookSendMail Wrapper Script", "Mail successfully sent to user '" & $sCurrentUser & "'!") _OL_Close($oOutlook) EndFunc Func _ChecklogFile() $FiletoCheck_2 = FileGetTime($logfile, 0, 1) ; Timestamp If $FiletoCheck_1 == $FiletoCheck_2 Then ; if the time stamp has not changed Msgbox("","","File has not changed") _SendAlert() Else Msgbox("","","File has changed") EndIf EndFunc ; Initial Launch, grab current GetTime $FiletoCheck_1 = FileGetTime($logfile,0,1) Local $YYYY = StringLeft ( $FiletoCheck_1, 4 ) Local $MM = StringMid ( $FiletoCheck_1,5,2) Local $DD = StringMid ( $FiletoCheck_1,7,2 ) Local $HH = StringMid ( $FiletoCheck_1,9,2 ) Local $Min = StringMid ( $FiletoCheck_1,11,2 ) Local $SS = StringMid ( $FiletoCheck_1,13,2 ) $LastModTimeStamp = $YYYY&"-"&$MM&"-"&$DD&" "&$HH&":"&$Min&":"&$SS While 1 Sleep(60000) ; check every 10 mins _ChecklogFile() WEnd  

    • Wicked_Caty
      Program doesn't write to files
      By Wicked_Caty
      I've written a short program that calculates all values of a mathematical function in a user-defined interval. The data is written to an user-defined file during that process. Unfortunately, there is no file. I don't have a clue what's wrong with my program, and I've been trying to solve that for nearly 2 hours now. Obviously without success.
      The calculation is done properly (added a ConsoleWrite() to check that), so it must be the FileWrite() that doesn't work.
      Thanks for the help!
      Values.au3
    • k4rl3on
      [SOLVED] ClipGet() consumes 100% of CPU resources
      By k4rl3on
      hello
      I have problem with ClipGet () function: If the clipboard contains a large amount of data the use of the function pushes the consumption of cpu resources to 100% and my script unresponds until I force it to end.
      I tried to work around the problem by limiting the size of the recovered data from the clipboard

       
      Local = $ClipBoardData = StringMid(ClipGet (), 1.1024) I also used:

       
      DllCall ("psapi.dll", "int", "EmptyWorkingSet", "long", -1) to free the memory after each call to ClipGet ()
    • 31290
      File into list view and other
      By 31290
      Hi Everyone, Happy New Year
      Well, I have a script that gather information about a given switch here at work that output data in a txt file:

      What I'd like to do first is to put the file in a list view with the possibility to sort the ports by VLAN, by ports or by Status (and also delete all that concern Duplex / Speed / Type).
      In a second time, I'd like to bold and color "connected" in green / "disconnected" in red and "err-disabled" in gray. Then, I'd like also to apply a certain color depending on the VLAN number (I have the list of them).
      And to finish (sorry ^^) when I double click on a list item, I'd like to retrieve information of the selected line for me to do some operation on it.
      I know this is quite an ask but this is something I don't know how to (don't worry, I've done some researches before) do and also, I'm not familiar with arrays at all.
      Many thanks for those who can help

      I've uploaded the output txt file: EPES18.txt