Jump to content
Sign in to follow this  
CyNDeR

Need help with a simple script.

Recommended Posts

CyNDeR

I'm creating a small GUI ping utility that will ping a url/ip at a set interval and display the results on the GUI. I just can't figure out what type of GUI element to use to display the result. I'd like to have it store like the last 25 ping results. How would i go about doing this?


My scripts: Random Painter

Share this post


Link to post
Share on other sites
CyNDeR

Figured out how to use a listbox to do it. Is there a better way?


My scripts: Random Painter

Share this post


Link to post
Share on other sites
weaponx

Plain text edit box.

Share this post


Link to post
Share on other sites
FreeFry

or use a label

Share this post


Link to post
Share on other sites
CyNDeR

Now i feel stupid, lol. Can't figure out why it's not working, so here is my code so far:

#Include <GUIConstants.au3>
GUICreate("Pingy", 313, 232, 193, 125)
GUICtrlCreateLabel("++ Website/IP to ping.++", 40, 8, 131, 17)
$PingCount = 0
$URL = GUICtrlCreateInput("", 16, 32, 185, 21)
$StartPing = GUICtrlCreateButton("Ping!", 32, 64, 145, 57, 0)
$Results = GUICtrlCreateLabel("", 224, 40, 81, 177, $SS_BLACKFRAME)
$StopPing = GUICtrlCreateButton("Stop!", 32, 142, 145, 57, 0)
$PingCounter = GUICtrlCreateLabel("Ping Count: " & $PingCount, 224, 8, 80, 17)
GUISetState(@SW_SHOW)
While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $StartPing
            For $i = 1 To 5
                $Pinging = Ping($URL)
                GUICtrlSetData($Results, "TTL: " & $Pinging)
                $PingCount = $PingCount + 1
                GUICtrlSetData($PingCounter, "Ping Count: " & $PingCount)
            Next
    EndSwitch
WEnd

A few problems. The $Results label doesnt work, the GUI is very sluggish, and i can't figure out how to get the stop button to work correctly. It's been awhile since i've even seen AutoIt code so i'm sure i'm just missing something stupid.


My scripts: Random Painter

Share this post


Link to post
Share on other sites
rasim

Try this:

#Include <GUIConstants.au3>

GUICreate("Pingy", 313, 232, 193, 125)

GUICtrlCreateLabel("++ Website/IP to ping.++", 40, 8, 131, 17)

Dim $PingCount = 0

$URL = GUICtrlCreateInput("", 16, 32, 185, 21)

$StartPing = GUICtrlCreateButton("Ping!", 32, 64, 145, 57, 0)

$group = GUICtrlCreateGroup("Result", 224, 25, 81, 177, $BS_CENTER)
DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($group), "wstr", "", "wstr", "")

$Results = GUICtrlCreateLabel("", 229, 50, 70, 17)
GUICtrlSetFont(-1, Default, 800)
GUICtrlSetColor(-1, 0x008000)

$StopPing = GUICtrlCreateButton("Stop!", 32, 142, 145, 57, 0)

$PingCounter = GUICtrlCreateLabel("Ping Count: " & $PingCount, 224, 8, 80, 17)

GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $StartPing
            _Ping()
            
    EndSwitch
WEnd

Func _Ping()
    Local $Pinging, $i
    For $i = 1 To 5
        $Pinging = Ping(GUICtrlRead($URL))
        If GUIGetMsg() = $StopPing Then Return 0
        GUICtrlSetData($Results, "TTL: " & $Pinging)
        $PingCount = $PingCount + 1
        GUICtrlSetData($PingCounter, "Ping Count: " & $PingCount)
    Next
EndFunc
Edited by rasim

Share this post


Link to post
Share on other sites
CyNDeR

Thanks! It works good except for a couple things. First, i'd like to display the result of each ping in a list of sorts, not just display the last result. Also, for some reason the Ping Counter doesnt reset when the start button is pressed. I'd like to write the code myself, if you could just point me in the right direction. :D


My scripts: Random Painter

Share this post


Link to post
Share on other sites
rasim

Like this?

#include <GUIConstants.au3>
#include <GuiListBox.au3>

$hGui = GUICreate("Pingy", 313, 232, 193, 125)

GUICtrlCreateLabel("++ Website/IP to ping.++", 40, 8, 131, 17)

Dim $PingCount = 0

$URL = GUICtrlCreateInput("", 16, 32, 185, 21)

$StartPing = GUICtrlCreateButton("Ping!", 32, 64, 145, 57, 0)

$StopPing = GUICtrlCreateButton("Stop!", 32, 142, 145, 57, 0)

$PingCounter = GUICtrlCreateLabel("Ping Count: " & $PingCount, 224, 8, 80, 17)

$ClearButton = GUICtrlCreateButton("Clear", 224, 210, 81, 20)

$hListBox = _GUICtrlListBox_Create($hGui, "", 224, 32, 81, 182, BitOR($WS_VSCROLL, $LBS_NOSEL))

GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $StartPing
            If GUICtrlRead($URL) = '' Then
                MsgBox(16, "Error", "Please type web address")
                GUICtrlSetState($URL, $GUI_FOCUS)
                ContinueCase
            EndIf
            _Ping()
        Case $ClearButton
            If _GUICtrlListBox_GetCount($hListBox) > 0 Then
                _GUICtrlListBox_ResetContent($hListBox)
                GUICtrlSetData($PingCounter, "Ping Count: 0")
                $PingCount = 0
            EndIf
        EndSwitch
    WEnd

Func _Ping()
    Local $Pinging, $i
    For $i = 1 To 5
        $Pinging = Ping(GUICtrlRead($URL))
        If GUIGetMsg() = $StopPing Then Return 0
        _GUICtrlListBox_AddString($hListBox, $Pinging)
        $PingCount += 1
        GUICtrlSetData($PingCounter, "Ping Count: " & $PingCount)
    Next
EndFunc

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
Sign in to follow this  

×