本帖最后由 komaau3 于 2013-11-8 13:28 编辑
回复 1# LiYi1987
查了下资料,翻译成AU3,测试可以实现模拟拖拽(代码示例把“CDkey.txt拖到记事本窗口”)
原文:http://huidaqq.blog.163.com/blog/static/35643562200981893849626/#include <WindowsConstants.au3>
#Include <WinAPI.au3>
#Include <Memory.au3>
#include <SendMessage.au3>
Local $hWnd = WinGetHandle("新建 文本文档.txt - 记事本")
Local $Bool = DropFile($hWnd ,@ScriptDir & "\CDKey.txt")
MsgBox(0, 0, $Bool)
Func DropFile($hWnd ,$sFile)
;typedef struct _DROPFILES {
; DWORD pFiles;
; POINT pt;
; BOOL fNC;
; BOOL fWide;
;} DROPFILES, *LPDROPFILES;
If Not FileExists($sFile) Or Not IsHWnd($hWnd) Then Return False
Local $iProcess = WinGetProcess($hWnd)
Local $hProcess = _WinAPI_OpenProcess(BitOR($PROCESS_VM_OPERATION, $PROCESS_VM_READ, $PROCESS_VM_WRITE), False, $iProcess)
Local $vPointer = _MemVirtualAllocEx($hProcess, Null, 4096, BitOR($MEM_RESERVE, $MEM_COMMIT), $PAGE_READWRITE)
Local $tagDROPFILES = "dword pFiles;" & $tagPOINT & ";bool fNC;bool fWide"
Local $tagWRITEDATA = $tagDROPFILES & ";wchar[" & StringLen($sFile) + 1 & "]"
Local $tDropFiles = DllStructCreate($tagDROPFILES)
Local $tWriteData = DllStructCreate($tagWRITEDATA);一次写入
DllStructSetData($tWriteData, "pFiles", DllStructGetSize($tDropFiles))
DllStructSetData($tWriteData, "X", 0)
DllStructSetData($tWriteData, "Y", 0)
DllStructSetData($tWriteData, "fNC", 0)
DllStructSetData($tWriteData, "fWide", 1)
DllStructSetData($tWriteData, 6, $sFile)
Local $iWritten
_WinAPI_WriteProcessMemory($hProcess, $vPointer, DllStructGetPtr($tWriteData), DllStructGetSize($tWriteData), $iWritten)
_SendMessage($hWnd, $WM_DROPFILES, $vPointer, 0)
_MemVirtualFreeEx($hProcess, $vPointer, 0, $MEM_RELEASE);
_WinAPI_CloseHandle($hProcess)
Return True
EndFunc
|