#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1) ; 切换为 OnEvent 模式
HotKeySet("{Esc}", "tingzhi") ;热键设置停止循环
Dim $a,$x,$i,$d,$tt,$dll,$Timer,$TimerDLL,$tm ,$tip,$Pm
$Form1 = GUICreate("Form1", 820, 620, 100, 50)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
$Edit1 = GUICtrlCreateEdit("", 5, 64, 401, 550,$ES_WANTRETURN)
$Edit2 = GUICtrlCreateEdit("", 415, 64, 401, 550,$ES_WANTRETURN)
;BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN))
;-------------------------
$filetext1 = "数据不够自行复制粘贴5B30303039434645435D204C6F6164696E6720446576696365203D2048494D454D2E5359530D0A284C6F676F2064" & _
"697361626C6564290D0A5B30303039434645435D204C6F616453756363657373202020203D2048494D454D2E5359530D0A5B3" & _
"720446576696365203D20474344524F4D2E5359530D0A5B30303039443033375D204C6F61644661696C656420202020203D2047" & _
"0303039434645435D204C6F6164696E6720446576696365203D20514344524F4D2E5359530D0A5B30303039434645445D204C6" & _
"F61645375636365737320202"
$filetext2 = "数据不够自行复制粘贴5B30303039434646465D204C6F6164696E6720446576696365203D20474344524F4D2E5359530D0A5B30303039443" & _
"031335D204C6F61644661696C656420202020203D20474344524F4D2E5359530D0A5B30303039443032335D204C6F6164696E6" & _
"0303039434645435D204C6F6164696E6720446576696365203D20514344524F4D2E5359530D0A5B30303039434645445D204C6" & _
"720446576696365203D20474344524F4D2E5359530D0A5B30303039443033375D204C6F61644661696C656420202020203D2047" & _
"4344524F4D2E5359530D0A"
GUICtrlSetData($Edit1,$filetext1)
GUICtrlSetData($Edit2,$filetext2)
ControlFocus ("Form1","",$Edit1)
Send("^{Home}")
;--------------------------
$Button1 = GUICtrlCreateButton("比较", 5, 16, 75, 25)
$Button2 = GUICtrlCreateButton("停止", 105, 16, 75, 25)
GUICtrlSetOnEvent($Button1, "huoquData1")
GUICtrlSetOnEvent($Button2, "tingzhi")
;-----------------------------------------------
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
;AdlibRegister( "detect",250) ;自定义监控函数
GUISetState(@SW_SHOW)
While 1
Sleep(1)
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func huoquData1()
$x = 0 ;循环启动标识
$tt = 0 ;循环运行标识
$tm = 0
$tip = 0
;AdlibRegister( "detect",250) ;自定义监控函数 ,此函数的问题是,不可以取消事件,考虑用定时器
If $tt = 0 Then
$dll = DllOpen("user32.dll")
$Timer = DllCallbackRegister("Timer", "int", "hwnd;uint;uint;dword")
$TimerDLL = DllCall($dll, "uint", "SetTimer", "hwnd", 0, "uint", 0, "int", 10, "ptr", DllCallbackGetPtr($Timer))
EndIf
$GetData1 = GUICtrlRead ($Edit1)
$GetData2 = GUICtrlRead ($Edit2)
$RightDataA = StringLen($GetData1) ;最后一个字符的位置
$a = 0
$d = $RightDataA
For $i =1 To $d Step 1
Sleep(100)
If $x = 1 Then
$tt = 1
Return
EndIf
$a = $a + 1
;-------------移动------
ControlFocus ("Form1","",$Edit1)
If $a-1 = 0 Then Send("^{Home}")
Send("{RIGHT " & $a-1 & "}") ; 移动插入点前位置
;-------------移动------
If $x = 1 Then
$tt = 1
Return
EndIf
$MidDataA = StringMid ($GetData1,$a,1)
$MidDataB = StringMid ($GetData2,$a,1)
$ComData = StringCompare ($MidDataA,$MidDataB,1) ;比较两个数值
If $x = 1 Then Return
If $ComData <> 0 Then
$tip = $tip + 1
TrayTip("循环中","发现" & $tip &"处不同",10, 1)
If $x = 1 Then
$tt = 1
Return
EndIf
EndIf
If $x = 1 Then
$tt = 1
Return
EndIf
Next
EndFunc
Func tingzhi()
$x = 1
EndFunc
Func CLOSEClicked()
GUIDelete()
Exit
EndFunc
Func WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
If $lParam = GUICtrlGetHandle($Button2) Then $Pm = 1
If $x = 0 And $lParam = GUICtrlGetHandle($Button2) Then
$x = 1
EndIf
EndFunc
Func Timer($hWnd, $uiMsg, $idEvent, $dwTime)
If $x = 0 And $Pm = 1 Then
$x = 1
EndIf
If $tm = 0 Then
If $x = 1 Then
$tm = 1 ;不进行二次操作
;MsgBox(0,"","测试",1)
timeclose() ;关闭定时器
EndIf
Else
EndIf
EndFunc
Func timeclose()
DllCall($dll, "int", "KillTimer", "hwnd", 0, "uint", $TimerDLL)
DllCallbackFree($Timer)
DllClose($dll)
MsgBox(0,"","FOR循环已停止!")
EndFunc