I have simple A.txt file and I would like to drag & drop it into another window. How can I do that ? Thanks for any help.
Let me explain some of my searches:
https://autohotkey.com/board/topic/41467-make-ahk-drop-files-into-other-applications/page-2
https://www.autohotkey.com/boards/viewtopic.php?f=5&t=38670
Code: Select all
DropFiles( FileList, wTitle="", Ctrl="", X=200, Y=200, NCA=0 )
{
characterSize := A_IsUnicode ? 2 : 1
StringReplace, FileList, FileList, `r`n, `n , All
VarSetCapacity( DROPFILES,20,32 ), DROPFILES.=FileList "`n`n", nSize:=StrLen(DROPFILES)*characterSize
StringReplace, DROPFILES,DROPFILES, `n,`n, UseErrorLevel
Loop %ErrorLevel%
NumPut( 0, DROPFILES, InStr(DROPFILES,"`n",0,0)*characterSize - characterSize, A_IsUnicode ? "Short" : "Char" )
pDP := &DROPFILES
NumPut(20, pDP+0)
NumPut(X, pDP+4)
NumPut(Y, pDP+8)
NumPut(NCA, pDP+12)
NumPut(A_IsUnicode ? 1 : 0, pDP+16)
hDrop := DllCall( "GlobalAlloc", UInt,0x42, UInt, nSize )
pData := DllCall( "GlobalLock", UInt, hDrop)
DllCall( "RtlMoveMemory", UInt,pData, UInt,pDP, UInt, nSize )
DllCall( "GlobalUnlock", UInt,hDrop )
PostMessage, 0x233, hDrop, 0, %Ctrl%, %wTitle% ; WM_DROPFILES := 0x233
}
HDrop(fnames,x=0,y=0)
{
characterSize := A_IsUnicode ? 2 : 1
fns:=RegExReplace(fnames,"\n$")
fns:=RegExReplace(fns,"^\n")
hDrop:=DllCall("GlobalAlloc","UInt",0x42,"UInt",20+(StrLen(fns)*characterSize)+characterSize*2)
p:=DllCall("GlobalLock","UInt",hDrop)
NumPut(20, p+0) ;offset
NumPut(x, p+4) ;pt.x
NumPut(y, p+8) ;pt.y
NumPut(0, p+12) ;fNC
NumPut(A_IsUnicode ? 1 : 0, p+16) ;fWide
p2:=p+20
Loop,Parse,fns,`n,`r
{
DllCall("RtlMoveMemory","UInt",p2,"Str",A_LoopField,"UInt",StrLen(A_LoopField)*characterSize)
p2+=StrLen(A_LoopField)*characterSize + characterSize
}
DllCall("GlobalUnlock","UInt",hDrop)
Return hDrop
}
PostMessage, 0x233, HDrop("C:\A.txt"), 0,, ahk_class Notepad
Code: Select all
SetTitleMatchMode, 2
list_files:={} ;define array name
data=
(
C:\A.txt
)
loop,parse,data,`n,`r
list_files[A_Index]:=A_LoopField
DropFiles("ahk_class Notepad", list_files)
DropFiles(window, files)
{
for k,v in files
memRequired+=StrLen(v)+1
hGlobal := DllCall("GlobalAlloc", "uint", 0x42, "ptr", memRequired+21)
dropfiles := DllCall("GlobalLock", "ptr", hGlobal)
NumPut(offset := 20, dropfiles+0, 0, "uint")
for k,v in files
StrPut(v, dropfiles+offset, "utf-8"), offset+=StrLen(v)+1
DllCall("GlobalUnlock", "ptr", hGlobal)
PostMessage, 0x233, hGlobal, 0,, %window%
if ErrorLevel
DllCall("GlobalFree", "ptr", hGlobal)
}
Both code just work perfect but only for Notepad window. Whenever I am trying to change it to "ahk_class X ( X the window that I wanted to drop it )" code is not work for me. Most probably it's about to droping into specific coordinate ( like X=100 Y=100) arena into that Window. However when I also changed X,Y coordinate that include into these codes it still not work for me. Any solution to do it?
Please help me and it's really importand for me, I have been searching for it like two weeks. I have no idea how can I do it. I don't know how to write codes. Thank you all!