#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <String.au3>
Opt('GUIOnEventMode', 1)
Opt('TrayAutoPause',0)
Opt('TrayMenuMode',1)
Opt('TrayIconHide',0) ;不隐藏
$g_szVersion = "My Script 1.1"
If WinExists($g_szVersion) Then Exit MsgBox(16,"提示","程序已运行了!",2); 此脚本已经运行了
AutoItWinSetTitle($g_szVersion)
Local $file="D:\XH-1\ZZZ"
If Not FileExists("D:\XH-1\ZZZ") Then Exit MsgBox(64,"提示","文件不存在!",5)
$Form1 = GUICreate("Form1", 951, 622)
GUISetOnEvent(-3, '_Exit')
$Group1 = GUICtrlCreateGroup("当前zzz文件内容如下:", 16, 16, 921, 553)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Edit2 = GUICtrlCreateEdit("", 21, 48, 908, 508)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
;$Label2 = GUICtrlCreateLabel("", 21, 48, 508, 108)
;GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Label1 = GUICtrlCreateLabel("修改样品标注为:", 132, 580, 149, 28)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Input1 = GUICtrlCreateInput("", 311, 580, 201, 32,0x2000)
$hInput1 = GUICtrlGetHandle($Input1)
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("修改并保存", 608, 572, 97, 41)
GUISetState(@SW_SHOW)
GUIRegisterMsg(0x0111, 'WM_COMMAND')
wri()
GUICtrlSetOnEvent($Button1, "diy")
While 1
Sleep(1000)
WEnd
Func wri()
Local $ff=FileRead($file)
GUICtrlSetData($Edit2,$ff)
Local $f1=FileRead($file)
Local $f11=StringRegExp($f1, '样品标注:(\d*)', 1)
If Not @error Then Local $ss=$f11[0]
GUICtrlSetData($Input1,$ss)
GUICtrlSetState($Button1, $GUI_DEFBUTTON) ;设置默认按钮
;ControlFocus($Form1, "", $Input1) ;设置输入焦点到窗口的指定控件
EndFunc
Func diy()
If Not GUICtrlRead($Input1) Then
GUISetState(@SW_DISABLE,$Form1)
MsgBox(262144,"提示","输入有误或者为空,请检查后再执行!",3)
GUISetState(@SW_ENABLE,$Form1)
ElseIf StringLen(GUICtrlRead($Input1)) <> 6 Then
GUISetState(@SW_DISABLE,$Form1)
MsgBox(262144,"提示","输入的位数可能不对,请检查后再执行!",3)
GUISetState(@SW_ENABLE,$Form1)
Else
Local $f1=FileRead($file)
Local $f11=StringRegExp($f1, '样品标注:(\d*)', 1)
If Not @error Then Local $ss=$f11[0]
If @error Then Exit
$str=StringRegExpReplace($f1, '(样品标注:)[\d\h]{6}(?=\h+)', '${1}' & GUICtrlRead($Input1))
Local $dk = FileOpen($File, 2)
FileWrite($dk,$str)
GUICtrlSetData($Edit2,$str)
FileClose($dk)
EndIf
EndFunc
Func _Exit()
Exit
EndFunc ;==>_Exit
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg
If $ilParam = $hInput1 And BitShift($iwParam, 16) = 256 Then GUICtrlSetState($Input1, 256)
EndFunc ;==>WM_COMMAND