Jump to content

GUI list view help


mjg
 Share

Recommended Posts

Ok, here is what I have so far:

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <Constants.au3>
#include <GUIConstants.au3>

Dim $line

$GUI = GUICreate("Site Connections", 400 , 325)
$view = GUICtrlCreateListView ("Site                |Status|Latency", 10, 30, 370, 279)

GUISetState (@SW_SHOW) 

$time = ping("192.168.55.1",10)
    If Not @error Then
        GuiCtrlCreateListViewItem("South View | UP! | "& $time &"ms",$view)
        GUICtrlSetImage(-1, "shell32.dll",19)
    Else
        GUICtrlCreateListViewItem("South View| DOWN | n/a",$view)
        GUICtrlSetImage(-1, "shell32.dll",240)
    EndIf
Sleep(100)

What I would like to happen is to have the ping refresh every five seconds. Due to my complete lack of knowledge, the only way I know how to do this is by using the sleep command. In addition to that, is it possible so that it just writes over its current spot on line 1? I'd like to add other sites later, which is why I want their location to be static.

On a side note, I have noticed when I added other sites, sometimes the other site pings are extremely high, is that because I'm trying to ping too many things too fast?

Thanks for your help,

-mjg

Link to comment
Share on other sites

Ok, here is what I have so far:

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <Constants.au3>
#include <GUIConstants.au3>

Dim $line

$GUI = GUICreate("Site Connections", 400 , 325)
$view = GUICtrlCreateListView ("Site                |Status|Latency", 10, 30, 370, 279)

GUISetState (@SW_SHOW) 

$time = ping("192.168.55.1",10)
    If Not @error Then
        GuiCtrlCreateListViewItem("South View | UP! | "& $time &"ms",$view)
        GUICtrlSetImage(-1, "shell32.dll",19)
    Else
        GUICtrlCreateListViewItem("South View| DOWN | n/a",$view)
        GUICtrlSetImage(-1, "shell32.dll",240)
    EndIf
Sleep(100)

What I would like to happen is to have the ping refresh every five seconds. Due to my complete lack of knowledge, the only way I know how to do this is by using the sleep command. In addition to that, is it possible so that it just writes over its current spot on line 1? I'd like to add other sites later, which is why I want their location to be static.

On a side note, I have noticed when I added other sites, sometimes the other site pings are extremely high, is that because I'm trying to ping too many things too fast?

Thanks for your help,

-mjg

Something like this may work for you; you could possibly put all of your hosts in an array and delete them as they are used, but as you only gave one example, i only coded for one :D

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <Constants.au3>
#include <GUIConstants.au3>

Dim $line
dim $item
$GUI = GUICreate("Site Connections", 400 , 325)
$view = GUICtrlCreateListView ("Site                |Status|Latency", 10, 30, 370, 279)

GUISetState (@SW_SHOW)
$c = 0
func getPings()
$time = ping("www.google.com",10)
    if $time Then
        $item = GuiCtrlCreateListViewItem("South View | UP! | "& $time &"ms",$view)
        GUICtrlSetImage(-1, "shell32.dll",19)
    Else
        $item = GUICtrlCreateListViewItem("South View| DOWN | n/a",$view)
        GUICtrlSetImage(-1, "shell32.dll",240)
    EndIf
EndFunc
        call("getPings")
$begin = TimerInit()
while 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        
        case Else
            $diff = TimerDiff($begin)
            if $diff > 5000 Then
                $begin = TimerInit()
                GUICtrlDelete($item)
                call("getPings")
            EndIf
    EndSwitch
WEnd

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

'Good suggestion on the array, can you show me a sample code where I could utilize an array for the sites and have them all display and refresh on the screen?

Here is a way to do it with an array, using sites.txt as your template. Note, the way the regex is setup, the sites.txt has to be formated like: SITE, NAME (note the comma and space). But it will refresh every 10 seconds (which you can change at the top of the script.

Hope that helped :D

--zack

#include <file.au3>
#include <array.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <Constants.au3>
#include <GUIConstants.au3>
#RequireAdmin

Global $refresh = 10000

Dim $sites
if not FileExists("sites.txt") then call("_MakeList")
_FileReadToArray("sites.txt", $sites)

$GUI = GUICreate("Site Connections", 400 , 325)
$view = GUICtrlCreateListView ("Site                |Status|Latency", 10, 30, 370, 279)
GUISetState (@SW_SHOW)

call("_Ping")
$begin = TimerInit()
while 1
    $msg = GUIGetMsg()
    switch $msg
        case $GUI_EVENT_CLOSE
            Exit
        case Else
             $diff = TimerDiff($begin)
            if $diff > $refresh Then
                $begin = TimerInit()
                GUICtrlDelete($view)
                $view = GUICtrlCreateListView ("Site                |Status|Latency", 10, 30, 370, 279)
                call("_Ping")
            EndIf
    EndSwitch
WEnd

Func _Ping()
$nOffset = 1
for $x = 1 to UBound($sites) - 1
        $array = StringRegExp($sites[$x], '(?i)(?s)(.*?),\s(.*?)(?:\z)', 1, $nOffset)
        $site = $array[0]
        $name = $array[1]
        $var = ping($site, 250)
        if $var Then
            GuiCtrlCreateListViewItem($name&" | UP! | "& $var &"ms", $view)
            GUICtrlSetImage(-1, "shell32.dll",19)
        Else
            GuiCtrlCreateListViewItem($name&" | Down! | "& $var &"ms", $view)
            GUICtrlSetImage(-1, "shell32.dll",240)
        EndIf
    Next
EndFunc


func _MakeList()
    $file = fileopen("sites.txt", 2)
    FileWrite($file, "www.google.com, Google"&@CRLF)
    FileWrite($file, "www.apple.com, Apple"&@CRLF)
    FileWrite($file, "www.autoit.com, Auto.IT"&@CRLF)
    FileWrite($file, "www.bettertrades.com, BetterTrades"&@CRLF)
    FileWrite($file, "www.home.com, Home"&@CRLF)
    FileWrite($file, "www.homedepot.com, HomeDepot"&@CRLF)
    FileWrite($file, "www.time.com, Time"&@CRLF)
    FileWrite($file, "61.151.253.88, Yule"&@CRLF)
    FileWrite($file, "208.96.51.15, Tired")
    FileClose($file)
EndFunc
Edited by zackrspv

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
Share on other sites

Hi Zackrspv,

A nice script there...While looking for something in the forums, I found your post. So I wanted to try your code to monitor my server. I had to add @crlf at the end of each Filewrite commands (except for the last one) of the _MakeList function to have the listview populated correctly. Without this, it was all on the same row...

Except for that , it works perfectly !!

Have a nice day !

Link to comment
Share on other sites

Hi Zackrspv,

A nice script there...While looking for something in the forums, I found your post. So I wanted to try your code to monitor my server. I had to add @crlf at the end of each Filewrite commands (except for the last one) of the _MakeList function to have the listview populated correctly. Without this, it was all on the same row...

Except for that , it works perfectly !!

Have a nice day !

haha noted and changed; i wrote that pretty quickly so i overlooked that part. Thanks for the catch.

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...