#include <array.au3>
#include <file.au3>
#include <CoProc.au3> ;多进程udf
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("小鹤码表比对器", 380, 220,492, 124)
Global $Label1 = GUICtrlCreateLabel("请选择旧码表:", 16, 16, 116, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
Global $Input1 = GUICtrlCreateInput("", 64, 40, 233, 25)
Global $Button1 = GUICtrlCreateButton("选择文件", 304, 40, 57, 25)
Global $Input2 = GUICtrlCreateInput("", 64, 112, 233, 25)
Global $Button2 = GUICtrlCreateButton("选择文件", 304, 112, 57, 25)
Global $Button3 = GUICtrlCreateButton("开始比较", 72, 152, 225, 41)
Global $Label2 = GUICtrlCreateLabel("请选择新码表:", 16, 85, 116, 24)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
Global $Label3 = GUICtrlCreateLabel("已比对0行数据", 80, 200, 300, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
Global $Label4 = GUICtrlCreateLabel("用时0秒", 305, 200, 100, 20)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Global $min=0,$sed=0
Global $var;传送多进程,用于通知开始计时
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
Local $file1=FileOpenDialog("请选择文件",@DesktopDir,"文本文件 (*.txt)" )
If @error Then
MsgBox(0,"","请重新选择!")
Else
GUICtrlSetData($Input1,$file1)
$Input1=$file1
EndIf
Case $Button2
Local $file2=FileOpenDialog("请选择文件",@DesktopDir,"文本文件 (*.txt)" )
If @error Then
MsgBox(0,"","请重新选择!")
Else
GUICtrlSetData($Input2,$file2)
$Input2=$file2
EndIf
Case $Button3
_CoProc("main")
_CoProcReciver("time") ;注册Reciver()函数来接收子进程传递过来的消息
EndSwitch
WEnd
Func main()
If $Input1="" Or $Input2="" Then
MsgBox(0,"提示","您还没有选择文件,请重新选择!",2)
Return;提前终止函数
EndIf
Local $txt1=FileOpen($Input1)
Local $txt2=FileOpen($Input2)
Local $num,$a=1
Local $array[$a][2];存放对比数据
Local $readline1=_FileCountLines($Input1)
Local $readline2=_FileCountLines($Input2)
;MsgBox(0,"",$readline1&@CRLF&$readline2)
If $readline1 > $readline2 Then
Local $count=$readline1
Else
$count=$readline2
EndIf
For $num=1 To $count
Local $line1,$line2
$line1=FileReadLine($txt1,$num)
$line2=FileReadLine($txt2,$num)
If $num=1 Then ;开始处理第一行数据时,开始计时
_CoProcSend($gi_CoProcParent,"1")
EndIf
If $line1<>$line2 Then
ReDim $array[$a][2]
$array[$a-1][0]=$line1
$array[$a-1][1]=$line2
$a+=1
EndIf
If Mod($num,1000)=0 Then
GUICtrlSetData($Label3,"共"&$count&"行,"&"已比对"&$num&"行数据")
EndIf
Next
FileClose($txt1)
FileClose($txt2)
_ArrayDisplay($array)
EndFunc
Func Time($B);计时
MsgBox(0,"",$B)
AdlibRegister("time_1",1000)
EndFunc
Func time_1()
Local $fen
$sed+=1
If $sed=60 Then
$sed=0
$min+=1
EndIf
If $min<10 Then
$fen="0"&$min
Else
$fen=$min
EndIf
If $sed<10 Then $sed="0"&$sed
GUICtrlSetData($Label1,$fen&":"&$sed)
EndFunc