本帖最后由 afan 于 2012-6-12 19:52 编辑 Opt('GUIOnEventMode', 1)
GUICreate('Ping…')
GUISetOnEvent(-3, '_Exit')
Local $iInput = GUICtrlCreateInput('ping 1.1.1.1', 2, 5, 396, 20)
Local $iEdit = GUICtrlCreateEdit('请输入命令后回车', 2, 26, 396, 350, 0x200000)
Local $iLb = GUICtrlCreateLabel('等待执行… ', 10, 380, 300, 12)
GUISetState()
GUIRegisterMsg(0x0111, '_WMCOMMAND')
While 1
Sleep(100)
WEnd
Func _WMCOMMAND($hWnd, $iMsg, $wParam)
#forceref $hWnd, $iMsg
If BitAND($wParam, 0x0000FFFF) = 1 And Not BitShift($wParam, 16) Then Return _Run_CMD()
EndFunc ;==>_WMCOMMAND
Func _Run_CMD()
GUICtrlSetData($iEdit, '')
GUICtrlSetData($iLb, '正在执行命令并回显…')
Local $iPid, $Error, $sLine, $ts = TimerInit()
$iPid = Run(@ComSpec & ' /c ' & GUICtrlRead($iInput), '', 0, 3)
While 1
$sLine = StdoutRead($iPid)
$Error = @error
GUICtrlSetData($iEdit, $sLine, 1)
If $Error Or Not ProcessExists($iPid) Then ExitLoop
Sleep(1)
WEnd
GUICtrlSetData($iLb, '命令完成,回显结束。耗时 ' & Round(TimerDiff($ts)) & ' 毫秒')
EndFunc ;==>_Run_CMD
Func _Exit()
Exit
EndFunc ;==>_Exit
|