AP1

I can't exit my script

7 posts in this topic

#1 ·  Posted (edited)

Hello,

I have this small script for pinging things. I can't figure out how to stop the while loop and exit the program using the X in the top right. I found this [https://www.autoitscript.com/wiki/Interrupting_a_running_function] but I can't get it to work correctly. 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <FontConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <File.au3>
#include <Array.au3>
#NoTrayIcon



$GUI = GUICreate('Ping Tool', 461, 279, 310, 180)
$Input1 = GUICtrlCreateInput('', 8, 32, 289, 24)
$Label1 = GUICtrlCreateLabel('Type in the hostname or IP:', 8, 12, 286, 20)
$Button1 = GUICtrlCreateButton("Start", 304, 32, 73, 21)
$Edit1 = GUICtrlCreateEdit('', 8, 64, 441, 201, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_VSCROLL,$WS_BORDER))
$Checkbox1 = GUICtrlCreateCheckbox("Stop", 384, 32, 65, 21, BitOR($GUI_SS_DEFAULT_CHECKBOX,$BS_PUSHLIKE))
$Checkbox2 = GUICtrlCreateCheckbox('continuous ping', 305, 8, 113, 25)
GUISetState(@SW_SHOW)
GUICtrlSetState($Checkbox2, $GUI_CHECKED)
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            GUICtrlSetState($Checkbox1, $GUI_UNCHECKED)
            GUICtrlSetState($Button1, $GUI_DISABLE)
            GUICtrlSetData($Edit1, '')
            _Ping()
    EndSwitch
WEnd

Func _Ping()
Local $DOS
Local $Message
If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then
    $DOS = Run(@ComSpec & ' /c Ping ' & GUICtrlRead($Input1) & ' -t', '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    ProcessWait($DOS)

        While 1
            Sleep(10)
            $Message = StdoutRead($DOS)
            GUICtrlSetData($Edit1, $Message, 1)
            If @error Then ExitLoop
            If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then ExitLoop
        WEnd

Else
    $DOS = Run(@ComSpec & ' /c Ping ' & GUICtrlRead($Input1), '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    ProcessWait($DOS)

        Local $i = 0
        Do
            Sleep(10)
            $Message = StdoutRead($DOS)
            GUICtrlSetData($Edit1, $Message, 1)
            If @error Then ExitLoop
            If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then ExitLoop
            $i += 1
        Until $i = 500
EndIf

ProcessClose($DOS)
GUICtrlSetState($Button1, $GUI_ENABLE)
_KillPing()
EndFunc

Func _KillPing()
    While ProcessExists('ping.exe')
        ProcessClose('ping.exe')
    WEnd
EndFunc

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) ; Hides the cursor in the Edit box
    Local $nNotifyCode = BitShift($wParam, 16)
    Switch $lParam
        Case GUICtrlGetHandle($Edit1)
            Switch $nNotifyCode
                Case $EN_SETFOCUS
                    DllCall('user32.dll', 'int', 'HideCaret', 'hwnd', $lParam) ; => _WinAPI_HideCaret($lParam)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Also, in the non-continuous ping code, I can't figure out how to exit the loop once the single ping command has run. I did a for-until as a workaround but there has to be a better way.

 

$DOS = Run(@ComSpec & ' /c Ping ' & GUICtrlRead($Input1), '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    ProcessWait($DOS)
        Local $i = 0
        Do
            Sleep(10)
            $Message = StdoutRead($DOS)
            GUICtrlSetData($Edit1, $Message, 1)
            If @error Then ExitLoop
            If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then ExitLoop
            $i += 1
        Until $i = 500

Still pretty new to AutoIT and programming in general.

Thanks.

AP1

Edited by Melba23
Added code tags

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Any particular reason why you are using command prompt ping vs the built in ping from autoit?

Wrote this in a few minutes the other day when we were wondering if a few terminals were dropping at all throughout the day..... it just runs in the tray, you'd have to build a GUI of course.

 

#include <Date.au3>

;~ #pragma compile(Icon, zzzPing.ico)

Dim $aErrors[5]

$aErrors[0] = "Unknown Error"
$aErrors[1] = "Host is Offline"
$aErrors[2] = "Host is unreachable"
$aErrors[3] = "Bad Destination"
$aErrors[4] = "Other (Unknown)"

Local $sTerm3, $sTerm4

Local $sLogName = "Ping Test - Term"

Do
    $sTerm3 = Ping("102.2.2.103",1000)
    If Not @Error Then
        WriteLog("Ping Term3 Successful.  Response Time: " & $sTerm3 & "ms","3")
    Else
        WriteLog("ERROR - Term3:" & $aErrors[@error],"3")
    EndIf

    Sleep(50)

    $sTerm4 = Ping("102.2.2.104",1000)
    If Not @Error Then
        WriteLog("Ping Term3 Successful.  Response Time: " & $sTerm4 & "ms","4")
    Else
        WriteLog("ERROR - Term4:" & $aErrors[@error],"4")
    EndIf

    Sleep(2000)

Until 1=0


Func WriteLog($sText,$iLogAppend = "")
    Local $sTmp = ""

    If Not FileCreate(@ScriptDir & "\" & $sLogName & $iLogAppend & ".log", _DateTimeFormat(_NowCalc(), 2) & " " & _DateTimeFormat(_NowCalc(), 5) & "  Ping Monitor" & @CRLF) Then

        MsgBox($MB_ICONERROR, "", "No log file exists, and an error occured while trying to create one!!!")
        Return False
    EndIf

    ; Open the file for writing (append to the end of a file) and store the handle to a variable.
    Local $hFileOpen = FileOpen(@ScriptDir & "\" & $sLogName & $iLogAppend & ".log", $FO_APPEND)
    If $hFileOpen = -1 Then
        MsgBox($MB_ICONERROR, "", "An error occurred when reading the file.")
        Return False
    EndIf

    If Isarray($sText) Then
        Local $i
        For $i = 0 to UBound($sText)-1
            $sTmp &= $sText[$i] & "  "
        Next
        $sText = $sTmp
    EndIf

    FileWriteLine($hFileOpen, _DateTimeFormat(_NowCalc(), 2) & " " & _DateTimeFormat(_NowCalc(), 5) & "  " & $sText)
    FileClose($hFileOpen)
EndFunc


Func FileCreate($sFilePath, $sString)
    Local $fReturn = True ; Create a variable to store a boolean value.
    If FileExists($sFilePath) = 0 Then $fReturn = FileWrite($sFilePath, $sString) = 1 ; If FileWrite returned 1 this will be True otherwise False.
    Return $fReturn ; Return the boolean value of either True of False, depending on the return value of FileWrite.
EndFunc   ;==>FileCreate

 

Edited by kaisies

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Welcome to the forum AP1.

Haven't tested the following for your first issue, but I have amended & improved your code a little.

Please use the <> button when you post code, so that it appears like the following, and is much easier for your helpers.

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            GUICtrlSetState($Checkbox1, $GUI_UNCHECKED)
            GUICtrlSetState($Button1, $GUI_DISABLE)
            GUICtrlSetState($Checkbox2, $GUI_DISABLE)
            GUICtrlSetData($Edit1, '')
            _Ping()
    EndSwitch
WEnd

Func _Ping()
    Local $DOS, $flag, $Message, $i = 0
    If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then
        $flag = ' -t'
    Else
        $flag = ''
    EndIf
    $DOS = Run(@ComSpec & ' /c Ping ' & GUICtrlRead($Input1) & $flag, '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    ProcessWait($DOS)
    
    While 1
        Sleep(10)
        $Message = StdoutRead($DOS)
        GUICtrlSetData($Edit1, $Message, 1)
        If @error Then ExitLoop
        $nMsg = GUIGetMsg()
        If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then ExitLoop
        If GUICtrlRead($Checkbox2) <> $GUI_CHECKED And $i = 500 Then ExitLoop
        $i += 1
    WEnd
    
    ProcessClose($DOS)
    GUICtrlSetState($Checkbox2, $GUI_ENABLE)
    GUICtrlSetState($Button1, $GUI_ENABLE)
    _KillPing()
EndFunc

P.S. If that doesn't solve your first issue, it should at least get you thinking in the right direction, where you need to look at $nMsg.

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

;~ #include <AutoItConstants.au3>
;~ #include <ButtonConstants.au3>
;~ #include <EditConstants.au3>
;~ #include <WindowsConstants.au3>
;~ #include <WinAPIConstants.au3>
;~ #include <GUIConstantsEx.au3>
#NoTrayIcon
Global Const $BS_RIGHT = 0x0200
Global Const $BS_RIGHTBUTTON = 0x0020
Global Const $ES_READONLY = 2048
Global Const $EN_SETFOCUS = 0x100
Global Const $WS_BORDER = 0x00800000
Global Const $WM_COMMAND = 0x0111
Global Const $GUI_SS_DEFAULT_EDIT = 0x003010c0
Global Const $GUI_RUNDEFMSG = 'GUI_RUNDEFMSG'
Global Const $GUI_EVENT_CLOSE = -3
Global Const $GUI_DISABLE = 128
Global Const $GUI_CHECKED = 1
Global Const $GUI_ENABLE = 64
Global Const $STDOUT_CHILD = 2
Global Const $STDERR_CHILD = 4
Global $hGUI = GUICreate("Ping Tool", 459, 275, -1, -1)
Global $ipDomain = GUICtrlCreateInput("192.168.1.1", 152, 8, 297, 21)
GUICtrlCreateLabel("Type in the hostname or IP:", 8, 12, 142, 20)
Global $bStart = GUICtrlCreateButton("Start", 152, 32, 145, 29)
Global $bStop = GUICtrlCreateButton("Stop", 312, 32, 137, 29)
Global $eLogView = GUICtrlCreateEdit("", 8, 64, 441, 201, BitOR($GUI_SS_DEFAULT_EDIT, $ES_READONLY, $WS_BORDER))
Global $cNonstop = GUICtrlCreateCheckbox("Continuous ping", 17, 32, 113, 25, BitOR($BS_RIGHTBUTTON, $BS_RIGHT))
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
Global $nMsg
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $bStart
            GUICtrlSetState($bStart, $GUI_DISABLE)
            _Ping()
            GUICtrlSetState($bStart, $GUI_ENABLE)
        Case $bStop
            _KillPing()
            GUICtrlSetState($bStart, $GUI_ENABLE)
    EndSwitch
WEnd
Func _Ping()
    Local $pDOS, $rMessage, $tNonstop
    GUICtrlSetData($eLogView, '')
    If GUICtrlRead($cNonstop) = $GUI_CHECKED Then $tNonstop = ' -t'
    Local $pDOS = Run(@ComSpec & ' /c Ping ' & GUICtrlRead($ipDomain) & $tNonstop, '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    ProcessWait($pDOS)
    While 1
        $rMessage = StdoutRead($pDOS)
        If @error Then ExitLoop
        GUICtrlSetData($eLogView, $rMessage, 1)
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                OnAutoItExit($pDOS)
            Case $bStop
                _KillPing($pDOS)
                ExitLoop
        EndSwitch
        Sleep(1)
    WEnd
    ProcessClose($pDOS)
    _KillPing($pDOS)
EndFunc   ;==>_Ping
Func _KillPing($PING = "")
    If $PING = "" Then $PING = 'ping.exe'
    While ProcessExists($PING)
        ProcessClose($PING)
    WEnd
EndFunc   ;==>_KillPing
Func OnAutoItExit($PING)
    _KillPing($PING)
    Exit
EndFunc   ;==>OnAutoItExit
Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $nNotifyCode = BitShift($wParam, 16)
    Switch $lParam
        Case GUICtrlGetHandle($eLogView)
            Switch $nNotifyCode
                Case $EN_SETFOCUS
                    DllCall('user32.dll', 'int', 'HideCaret', 'hwnd', $lParam)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND
Edited by Trong

Regards,
 

Share this post


Link to post
Share on other sites

AP1,

Welcome to the AutoIt forums.

When you post code please use Code tags - see here how to do it.  Then you get a scrolling box and syntax colouring as you can see above now I have added the tags.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

@Trong. Nice. I added a counter to each ping line in the output so you can see progress when the pings linefeed on the screen:

;~ #include <AutoItConstants.au3>
;~ #include <ButtonConstants.au3>
;~ #include <EditConstants.au3>
;~ #include <WindowsConstants.au3>
;~ #include <WinAPIConstants.au3>
;~ #include <GUIConstantsEx.au3>
;~ #NoTrayIcon
Global Const $BS_RIGHT = 0x0200
Global Const $BS_RIGHTBUTTON = 0x0020
Global Const $ES_READONLY = 2048
Global Const $EN_SETFOCUS = 0x100
Global Const $WS_BORDER = 0x00800000
Global Const $WM_COMMAND = 0x0111
Global Const $GUI_SS_DEFAULT_EDIT = 0x003010c0
Global Const $GUI_RUNDEFMSG = 'GUI_RUNDEFMSG'
Global Const $GUI_EVENT_CLOSE = -3
Global Const $GUI_DISABLE = 128
Global Const $GUI_CHECKED = 1
Global Const $GUI_ENABLE = 64
Global Const $STDOUT_CHILD = 2
Global Const $STDERR_CHILD = 4
Global $hGUI = GUICreate("Ping Tool", 459, 275, -1, -1)
Global $ipDomain = GUICtrlCreateInput("192.168.1.1", 152, 8, 297, 21)
GUICtrlCreateLabel("Type in the hostname or IP:", 8, 12, 142, 20)
Global $bStart = GUICtrlCreateButton("Start", 152, 32, 145, 29)
Global $bStop = GUICtrlCreateButton("Stop", 312, 32, 137, 29)
Global $eLogView = GUICtrlCreateEdit("", 8, 64, 441, 201, BitOR($GUI_SS_DEFAULT_EDIT, $ES_READONLY, $WS_BORDER))
Global $cNonstop = GUICtrlCreateCheckbox("Continuous ping", 17, 32, 113, 25, BitOR($BS_RIGHTBUTTON, $BS_RIGHT))
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
Global $nMsg,$PingCount = -1
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $bStart
            GUICtrlSetState($bStart, $GUI_DISABLE)
            _Ping()
            GUICtrlSetState($bStart, $GUI_ENABLE)
        Case $bStop
            _KillPing()
            GUICtrlSetState($bStart, $GUI_ENABLE)
    EndSwitch
WEnd
Func _Ping()
    Local $pDOS, $rMessage, $tNonstop
    GUICtrlSetData($eLogView, '')
    If GUICtrlRead($cNonstop) = $GUI_CHECKED Then $tNonstop = ' -t'
    Local $pDOS = Run(@ComSpec & ' /c Ping ' & GUICtrlRead($ipDomain) & $tNonstop, '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    ProcessWait($pDOS)
    While 1
        $rMessage = StdoutRead($pDOS)
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                OnAutoItExit($pDOS)
            Case $bStop
                _KillPing($pDOS)
                $PingCount = -1
                ExitLoop
        EndSwitch
        If $rMessage == "" Then
            ;Do nothing
        ElseIf @error Then
            ExitLoop
        ElseIf $PingCount <= -1 Then
        $PingCount += 1
        Else
        $PingCount += 1
        GUICtrlSetData($eLogView, $PingCount & " " & $rMessage, 1)
        Sleep(1)
        EndIf
    WEnd
    ProcessClose($pDOS)
    _KillPing($pDOS)
EndFunc   ;==>_Ping
Func _KillPing($PING = "")
    If $PING = "" Then $PING = 'ping.exe'
    While ProcessExists($PING)
        ProcessClose($PING)
    WEnd
EndFunc   ;==>_KillPing
Func OnAutoItExit($PING)
    _KillPing($PING)
    Exit
EndFunc   ;==>OnAutoItExit
Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $nNotifyCode = BitShift($wParam, 16)
    Switch $lParam
        Case GUICtrlGetHandle($eLogView)
            Switch $nNotifyCode
                Case $EN_SETFOCUS
                    DllCall('user32.dll', 'int', 'HideCaret', 'hwnd', $lParam)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND
While 1
    Sleep(100)
WEnd

 


Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Maybe better: 

;~ #include <AutoItConstants.au3>
;~ #include <ButtonConstants.au3>
;~ #include <EditConstants.au3>
;~ #include <WindowsConstants.au3>
;~ #include <WinAPIConstants.au3>
;~ #include <GUIConstantsEx.au3>
;~ #NoTrayIcon
Global Const $BS_RIGHT = 0x0200
Global Const $BS_RIGHTBUTTON = 0x0020
Global Const $ES_READONLY = 2048
Global Const $EN_SETFOCUS = 0x100
Global Const $WS_BORDER = 0x00800000
Global Const $WM_COMMAND = 0x0111
Global Const $GUI_SS_DEFAULT_EDIT = 0x003010c0
Global Const $GUI_RUNDEFMSG = 'GUI_RUNDEFMSG'
Global Const $GUI_EVENT_CLOSE = -3
Global Const $GUI_DISABLE = 128
Global Const $GUI_CHECKED = 1
Global Const $GUI_ENABLE = 64
Global Const $STDOUT_CHILD = 2
Global Const $STDERR_CHILD = 4
Global $hGUI = GUICreate("Ping Tool", 459, 275, -1, -1)
Global $ipDomain = GUICtrlCreateInput("192.168.1.1", 152, 8, 297, 21)
GUICtrlCreateLabel("Type in the hostname or IP:", 8, 12, 142, 20)
Global $bStart = GUICtrlCreateButton("Start", 152, 32, 145, 29)
Global $bStop = GUICtrlCreateButton("Stop", 312, 32, 137, 29)
Global $eLogView = GUICtrlCreateEdit("", 8, 64, 441, 201, BitOR($GUI_SS_DEFAULT_EDIT, $ES_READONLY, $WS_BORDER))
Global $cNonstop = GUICtrlCreateCheckbox("Continuous ping", 17, 32, 113, 25, BitOR($BS_RIGHTBUTTON, $BS_RIGHT))
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_COMMAND, 'WM_COMMAND')
HotKeySet("{enter}", "_Ping")
Global $nMsg
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $bStart
            _Ping()
        Case $bStop
            _KillPing()
            GUICtrlSetState($bStart, $GUI_ENABLE)
    EndSwitch
WEnd

Func _Ping()
    GUICtrlSetState($bStart, $GUI_DISABLE)
    Local $pDOS, $rMessage, $tNonstop, $nPingCount = 0
    GUICtrlSetData($eLogView, '')
    If GUICtrlRead($cNonstop) = $GUI_CHECKED Then $tNonstop = ' -t'
    Local $pDOS = Run(@ComSpec & ' /c Ping ' & GUICtrlRead($ipDomain) & $tNonstop, '', @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    ProcessWait($pDOS)
    While 1
        $rMessage = StdoutRead($pDOS)
        If @error Then
            ExitLoop
        ElseIf StringLen(StringStripWS($rMessage, 8)) > 0 Then
            $nPingCount += 1
            If StringInStr($rMessage, "Pinging") And Not (StringInStr($rMessage, "Reply") Or StringInStr($rMessage, "Request")) Then
                $nPingCount -= 1
                If $nPingCount = 0 Then $nPingCount = ""
                GUICtrlSetData($eLogView, $nPingCount & " " & $rMessage, 1)
            ElseIf StringInStr($rMessage, "Pinging") And StringInStr($rMessage, "Reply") Then
                GUICtrlSetData($eLogView, StringReplace($rMessage, "Reply", $nPingCount & " Reply"), 1)
            ElseIf StringInStr($rMessage, "Pinging") And StringInStr($rMessage, "Request") Then
                GUICtrlSetData($eLogView, StringReplace($rMessage, "Request", $nPingCount & " Request"), 1)
            Else
                GUICtrlSetData($eLogView, $nPingCount & " " & $rMessage, 1)
            EndIf
        EndIf
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                OnAutoItExit($pDOS)
            Case $bStop
                _KillPing($pDOS)
                ExitLoop
        EndSwitch
        Sleep(1)
    WEnd
    ProcessClose($pDOS)
    _KillPing($pDOS)
    GUICtrlSetState($bStart, $GUI_ENABLE)
EndFunc   ;==>_Ping

Func _KillPing($PING = "")
    If $PING = "" Then $PING = 'ping.exe'
    While ProcessExists($PING)
        ProcessClose($PING)
    WEnd
EndFunc   ;==>_KillPing

Func OnAutoItExit($PING = "")
    _KillPing($PING)
    Exit
EndFunc   ;==>OnAutoItExit

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
    Local $nNotifyCode = BitShift($wParam, 16)
    Switch $lParam
        Case GUICtrlGetHandle($eLogView)
            Switch $nNotifyCode
                Case $EN_SETFOCUS
                    DllCall('user32.dll', 'int', 'HideCaret', 'hwnd', $lParam)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

 

Edited by Trong
add Press Enter to start

Regards,
 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now