#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ACN_HASH.au3>
Global $Hash, $FileHandle, $Filename, $Filename2, $Buffersize = 0x20000
$Form1 = GUICreate("多个Input文件拖曳判断", 364, 211, -1, -1, -1, $WS_EX_ACCEPTFILES)
$Button1 = GUICtrlCreateButton("浏览", 312, 4, 43, 25)
$Input2 = GUICtrlCreateInput("", 8, 40, 297, 21)
$Button2 = GUICtrlCreateButton("复制", 312, 36, 43, 25)
$Input1 = GUICtrlCreateInput("浏览或拖曳一个文件到这里", 8, 8, 297, 21)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
$Button3 = GUICtrlCreateButton("浏览2", 312, 67, 43, 25)
$Input3 = GUICtrlCreateInput("浏览或拖曳一个文件到这里", 8, 70, 297, 21)
GUICtrlSetState(-1, 8)
$Button4 = GUICtrlCreateButton("复制2", 312, 97, 43, 25)
$Input4 = GUICtrlCreateInput("", 8, 100, 297, 21)
$Filename = GUICtrlRead($Input1)
$Filename2 = GUICtrlRead($Input3)
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button2
ClipPut(GUICtrlRead($Input2))
MsgBox(0, "结果", "已将MD5值复制到剪贴板!", 2)
Case $Button1
$Filename = FileOpenDialog("选择文件", "", "所有文件(*.*)")
If @error <> 1 Then
GUICtrlSetData($Input1, $Filename)
MD5A()
EndIf
Case $GUI_EVENT_DROPPED
$_Filename = ControlCommand($Form1, '', $Input1, 'GetSelected', '')
$_Filename2 = ControlCommand($Form1, '', $Input3, 'GetSelected', '')
If $_Filename<>$Filename Then
If StringInStr($_Filename, "|") <> 0 Then
GUICtrlSetData($Input1, "浏览或拖曳一个文件到这里")
MsgBox(16, "错误", "一次只能拖曳一个文件!", 5)
GUICtrlSetData($Input1, $Filename)
Else
GUICtrlSetData($Input1, $_Filename)
MD5A()
$Filename = $_Filename
EndIf
ElseIf $_Filename2<>$Filename2 Then
If StringInStr($_Filename2, "|") <> 0 Then
GUICtrlSetData($Input3, "浏览或拖曳一个文件到这里")
MsgBox(16, "错误", "一次只能拖曳一个文件!", 5)
GUICtrlSetData($Input3, $Filename2)
Else
GUICtrlSetData($Input3, $_Filename2)
MD5B()
$Filename = $_Filename2
EndIf
EndIf
EndSwitch
WEnd
Func MD5A()
MsgBox(0, 0, 'MD5A')
GUICtrlSetData($Input2, "计算中,请稍等...")
$FileHandle = FileOpen($_Filename, 16)
$MD5CTX = _MD5Init()
For $i = 1 To Ceiling(FileGetSize($_Filename) / $Buffersize)
_MD5Input($MD5CTX, FileRead($FileHandle, $Buffersize))
Next
$Hash = _MD5Result($MD5CTX)
FileClose($FileHandle)
$Hash = StringTrimLeft($Hash, 2)
$Hash = StringUpper($Hash)
GUICtrlSetData($Input2, $Hash)
EndFunc ;==>MD5A
Func MD5B()
MsgBox(0, 0, 'MD5B')
GUICtrlSetData($Input4, "计算中,请稍等...")
$FileHandle = FileOpen($_Filename2, 16)
$MD5CTX = _MD5Init()
For $i = 1 To Ceiling(FileGetSize($_Filename2) / $Buffersize)
_MD5Input($MD5CTX, FileRead($FileHandle, $Buffersize))
Next
$Hash = _MD5Result($MD5CTX)
FileClose($FileHandle)
$Hash = StringTrimLeft($Hash, 2)
$Hash = StringUpper($Hash)
GUICtrlSetData($Input4, $Hash)
EndFunc ;==>MD5B