Sign in to follow this  
Followers 0
XiaolinDraconis

Controls not keeping previous settings

6 posts in this topic

Don't see why it won't keep the settings when Options() gets called, keeps reverting to unchecked radios and slider at 100 of 255. It should be reading the INI for those values each time it's called.

#NoTrayIcon
#include <Misc.au3>
#include <MsgBoxConstants.au3>
#include <TrayConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode.
Opt("TrayOnEventMode", 1) ; Enable TrayOnEventMode.

HotKeySet("^{SPACE}", "TapTimer")

If FileExists(".\OTPT.ini") Then
    Sleep(1000)
Else
    IniWrite("OTPT.ini", "AOT", "True", "1" & @CRLF)
    IniWrite("OTPT.ini", "Transparency", "Value", "204" & @CRLF & @CRLF & "Max Transparency Value = 255")
EndIf

$Toggle = 0
$AOT = IniRead("OTPT.ini", "AOT", "True", "1")
$Transparency = IniRead("OTPT.ini", "Transparency", "Value", "204")


TrayMenu()

Func TrayMenu()
    TrayCreateItem("Settings")
    TrayItemSetOnEvent(-1, "Options")

    TrayCreateItem("About")
    TrayItemSetOnEvent(-1, "About")

    TrayCreateItem("") ; Create a separator line.

    TrayCreateItem("Exit")
    TrayItemSetOnEvent(-1, "ExitScript")

    TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "Options") ; Display the About MsgBox when the tray icon is double clicked on with the primary mouse button.

    TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu.
EndFunc   ;==>TrayMenu

While 1
    Sleep(100) ; An idle loop.
WEnd

Func TapTimer()
    HotKeySet("^{SPACE}")
    $TapTime = 0
    While _IsPressed("20")
        Sleep(1000)
        $TapTime += 1
    WEnd
    If $TapTime < 3 Then
        OnTop()
        Sleep(500)
    Else
        Options()
        Sleep(500)
    EndIf
    HotKeySet("^{SPACE}", "TapTimer")
EndFunc   ;==>TapTimer

Func Options()

    $Form1 = GUICreate("Settings", 290, 142)
    $Radio1 = GUICtrlCreateRadio("", 119, 32, 17, 17)
    If $AOT = 1 Then
        GUICtrlSetData($Radio1, $GUI_CHECKED, $GUI_CHECKED)
    Else
        GUICtrlSetData($Radio1, $GUI_UNCHECKED, $GUI_UNCHECKED)
    EndIf
    $Radio2 = GUICtrlCreateRadio("", 168, 32, 17, 17)
    $Label1 = GUICtrlCreateLabel("ON", 96, 32, 20, 17)
    $Label2 = GUICtrlCreateLabel("OFF", 142, 30, 24, 17)
    $Slider = GUICtrlCreateSlider(13, 72, 255, 25)
    GUICtrlSetData(-1, $Transparency)
    GUICtrlSetLimit(-1, 255, 0)
    $Label3 = GUICtrlCreateLabel("-", 8, 72, 15, 17)
    $Label4 = GUICtrlCreateLabel("+", 269, 70, 10, 17)
    $Label5 = GUICtrlCreateLabel("Always On Top", 102, 3, 89, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $Label6 = GUICtrlCreateLabel("Transparency", 106, 56, 81, 17)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
    $OK = GUICtrlCreateButton("OK", 128, 104, 33, 33)
    GUISetState(@SW_SHOW)
    WinSetOnTop("Settings", "", 1)

    While 1
        WinActivate("Settings")
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUISetState(@SW_HIDE)
                ExitLoop
            Case $OK
                While GUICtrlRead($Radio1) = $GUI_UNCHECKED And GUICtrlRead($Radio2) = $GUI_UNCHECKED
                    Sleep(100)
                    ToolTip("Please Select ON/OFF State")
                    WinActivate("Settings")
                WEnd
                If GUICtrlGetState($Radio1) = $GUI_CHECKED Then
                    $AOT = 1
                    $Transparency = GUICtrlRead($Slider)
                Else
                    $AOT = 0
                    $Transparency = GUICtrlRead($Slider)
                EndIf
                IniWrite("OTPT.ini", "AOT", "True", $AOT)
                IniWrite("OTPT.ini", "Transparency", "Value", $Transparency)
                ToolTip("")
                GUISetState(@SW_HIDE)
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>Options

Func About()
    MsgBox($MB_OK, "About", "OnTopPeekThrough" & @CRLF & @CRLF & _
            "Press CTRL+SPACE to toggle" & @CRLF & _
            "Or hold 3 seconds for Options" & @CRLF & @CRLF & _
            "By: XiaolinDraconis")
EndFunc   ;==>About

Func OnTop()
    If $Toggle = 0 Then
        $Toggle = 1
        Set()
    Else
        $Toggle = 0
        Unset()
    EndIf
EndFunc   ;==>OnTop

Func Set()
    $WinTitle = WinGetTitle("[active]")
    WinSetOnTop($WinTitle, "", 1)
    WinSetTrans($WinTitle, "", $Transparency)
EndFunc   ;==>Set

Func Unset()
    $WinTitle = WinGetTitle("[active]")
    WinSetOnTop($WinTitle, "", 0)
    WinSetTrans($WinTitle, "", 255)
EndFunc   ;==>Unset

Func ExitScript()
    Exit
EndFunc   ;==>ExitScript

Share this post


Link to post
Share on other sites



Managed to fix the slider. Now working on radio buttons.

Share this post


Link to post
Share on other sites

apparently i didnt entirely fix it.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

apparently i didnt entirely fix it.

Try: 

If $AOT = 1 Then
        GUICtrlSetState($Radio1, $GUI_CHECKED)
    Else
        GUICtrlSetState($Radio1, $GUI_UNCHECKED)
    EndIf

Edit: A more elegant way to handle having a Tray menu and a GUI would be to have a single While loop where you listen for messages from Tray and from the GUI and handle it that way:

P.S. I fixed the issues you were having with the ini not updating and also added a label to the Transparency slider to show the selected number.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

Opt("TrayMenuMode", 3)
HotKeySet("^{SPACE}", "TapTimer")

Global $inifile = @ScriptDir & "\OTPT.ini", $transparency = 204, $AOT = 1, $Toggle = 0

If FileExists($inifile) Then
    $AOT = IniRead($inifile, "AOT", "True", "1")
    $transparency = IniRead($inifile, "Transparency", "Value", "204")
Else
    IniWrite($inifile, "AOT", "True", $AOT & @CRLF)
    IniWrite($inifile, "Transparency", "Value", $transparency & @CRLF & @CRLF & "Max Transparency Value = 255")
EndIf

#Region ### START $optionsGUI ###
$optionsGUI = GUICreate("Options", 365, 200, @DesktopWidth/2 - 365/2, @DesktopHeight/2 - 200/2)
$RadioON = GUICtrlCreateRadio("ON", 128, 40, 49, 17)
If $AOT = 1 Then GUICtrlSetState(-1, $GUI_CHECKED)
$RadioOFF = GUICtrlCreateRadio("OFF", 184, 40, 49, 17)
If $AOT = 0 Then GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateLabel("Always on top:", 116, 8, 120, 24)
GUICtrlSetFont(-1, 12, 800, 0)
GUICtrlCreateLabel("Transparency:", 96, 74, 117, 24)
GUICtrlSetFont(-1, 12, 800, 0)
$tlabel = GUICtrlCreateLabel($transparency, 216, 74, 117, 24)
GUICtrlSetFont(-1, 12, 800, 0)
$tSlider = GUICtrlCreateSlider(24, 112, 318, 45)
GUICtrlSetLimit(-1, 255, 0)
GUICtrlSetData(-1, $transparency)
$optionsBtn_okay = GUICtrlCreateButton("OK", 136, 160, 75, 25)
#EndRegion ### END $optionsGUI ###

$options = TrayCreateItem("Settings")
$about = TrayCreateItem("About")
TrayCreateItem("") ; Create a separator line.
$exit = TrayCreateItem("Exit")

While 1

    Local $tMsg = TrayGetMsg()
    Switch $tMsg
        Case $options
            GUISetState(@SW_SHOW, $optionsGUI)
        Case $about
            MsgBox(0, "About", "OnTopPeekThrough" & @CRLF & @CRLF & _
                    "Press CTRL+SPACE to toggle" & @CRLF & _
                    "Or hold 3 seconds for Options" & @CRLF &  @CRLF & _
                    "By: XiaolinDraconis")
        Case $exit
            Exit
    EndSwitch

    Local $gMsg = GUIGetMsg()
    Switch $gMsg
        Case $optionsBtn_okay
            If GUICtrlRead($RadioON) = $GUI_CHECKED Then
                IniWrite($inifile, "AOT", "True", 1)
            ElseIf GUICtrlRead($RadioOFF) = $GUI_CHECKED Then
                IniWrite($inifile, "AOT", "True", 0)
            EndIf
            IniWrite($inifile, "Transparency", "Value", GUICtrlRead($tlabel))
            GUISetState(@SW_HIDE, $optionsGUI)
        Case $tSlider
            $val = GUICtrlRead($tSlider)
            GUICtrlSetData($tlabel, $val)
        Case $GUI_EVENT_CLOSE
            GUISetState(@SW_HIDE, $optionsGUI)
    EndSwitch

WEnd

Func TapTimer()
    HotKeySet("^{SPACE}")
    $TapTime = 0
    While _IsPressed("20")
        Sleep(1000)
        $TapTime += 1
    WEnd
    If $TapTime < 3 Then
        OnTop()
    Else
        GUISetState(@SW_SHOW, $optionsGUI)
    EndIf
    HotKeySet("^{SPACE}", "TapTimer")
EndFunc   ;==>TapTimer

Func OnTop()
    If $Toggle = 0 Then
        $Toggle = 1
        Set()
    Else
        $Toggle = 0
        Unset()
    EndIf
EndFunc   ;==>OnTop

Func Set()
    $WinTitle = WinGetTitle("[active]")
    WinSetOnTop($WinTitle, "", 1)
    WinSetTrans($WinTitle, "", $Transparency)
EndFunc   ;==>Set

Func Unset()
    $WinTitle = WinGetTitle("[active]")
    WinSetOnTop($WinTitle, "", 0)
    WinSetTrans($WinTitle, "", 255)
EndFunc   ;==>Unset

I'll be honest I am not 100% sure with HotKeys and the way you have gone about handling the way the Hot Keys work to set window transparency etc, but it seems to work, albeit somewhat choppy.

Edited by mpower

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Try: 

If $AOT = 1 Then
        GUICtrlSetState($Radio1, $GUI_CHECKED)
    Else
        GUICtrlSetState($Radio1, $GUI_UNCHECKED)
    EndIf

Edit: A more elegant way to handle having a Tray menu and a GUI would be to have a single While loop where you listen for messages from Tray and from the GUI and handle it that way:

P.S. I fixed the issues you were having with the ini not updating and also added a label to the Transparency slider to show the selected number.

I'll be honest I am not 100% sure with HotKeys and the way you have gone about handling the way the Hot Keys work to set window transparency etc, but it seems to work, albeit somewhat choppy.

 

Very nice, thank you. I know the Hotkey thing is sloppy, but I didn't see another way to go about having the delay for opening the options. Think I'll turn that into a double tap instead of holding it. 

The double tap method I'm gonna use is still choppy, but also I need to work out some more issues. It doesn't seem to be saving the transparency setting properly, also it is applying the transparency setting to the Settings GUI. Pretty sure some of that if not all is coming from the way I setup the Hotkey.

I'll work it out, then post what I did when I'm done.

Edited by XiaolinDraconis

Share this post


Link to post
Share on other sites

Ok so the transparency issue was due to a mix up in the variables, and the hotkey method I chose was with If Then statements and that just didn't work well so I went with a Switch Case.

And TADA! Thanks again, oh and if you notice the hotkey has a variable now, that's for future adjustments, going to make it so the key can be changed.

Near Perfection

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

Opt("TrayMenuMode", 3)

Global $inifile = @ScriptDir & "\OTPT.ini", $val = IniRead($inifile,"Transparency","Value","204"), $transparency = 204, $AOT = 1, $Toggle = 0, $TapCount = 0, $Hotkey = "^{SPACE}"

HotKeySet($Hotkey, "TapTimer")

If FileExists($inifile) Then
    $AOT = IniRead($inifile, "AOT", "True", "1")
    $transparency = IniRead($inifile, "Transparency", "Value", "204")
Else
    IniWrite($inifile, "AOT", "True", $AOT & @CRLF)
    IniWrite($inifile, "Transparency", "Value", $transparency & @CRLF & @CRLF & "Max Transparency Value = 255")
EndIf

$optionsGUI = GUICreate("Options", 365, 200, @DesktopWidth / 2 - 365 / 2, @DesktopHeight / 2 - 200 / 2)
$RadioON = GUICtrlCreateRadio("ON", 128, 40, 49, 17)
If $AOT = 1 Then GUICtrlSetState(-1, $GUI_CHECKED)
$RadioOFF = GUICtrlCreateRadio("OFF", 184, 40, 49, 17)
If $AOT = 0 Then GUICtrlSetState(-1, $GUI_CHECKED)
GUICtrlCreateLabel("Always on top:", 116, 8, 120, 24)
GUICtrlSetFont(-1, 12, 800, 0)
GUICtrlCreateLabel("Transparency:", 96, 74, 117, 24)
GUICtrlSetFont(-1, 12, 800, 0)
$tlabel = GUICtrlCreateLabel($transparency, 216, 74, 117, 24)
GUICtrlSetFont(-1, 12, 800, 0)
$tSlider = GUICtrlCreateSlider(24, 112, 318, 45)
GUICtrlSetLimit(-1, 255, 0)
GUICtrlSetData(-1, $transparency)
$optionsBtn_okay = GUICtrlCreateButton("OK", 136, 160, 75, 25)

$options = TrayCreateItem("Settings")
$about = TrayCreateItem("About")
TrayCreateItem("") ; Create a separator line.
$exit = TrayCreateItem("Exit")

While 1
    Local $tMsg = TrayGetMsg()
    Switch $tMsg
        Case $options
            GUISetState(@SW_SHOW, $optionsGUI)
        Case $about
            MsgBox(0, "About", "OnTopPeekThrough" & @CRLF & @CRLF & _
                    "Press" & $Hotkey & "to toggle" & @CRLF & _
                    "Or double tap for Options" & @CRLF & @CRLF & _
                    "By: AutoIt V3")
        Case $exit
            Exit
    EndSwitch

    Local $gMsg = GUIGetMsg()
    Switch $gMsg
        Case $optionsBtn_okay
            If GUICtrlRead($RadioON) = $GUI_CHECKED Then
                IniWrite($inifile, "AOT", "True", 1)
            ElseIf GUICtrlRead($RadioOFF) = $GUI_CHECKED Then
                IniWrite($inifile, "AOT", "True", 0)
            EndIf
            IniWrite($inifile, "Transparency", "Value", GUICtrlRead($tlabel))
            GUISetState(@SW_HIDE, $optionsGUI)
        Case $tSlider
            $val = GUICtrlRead($tSlider)
            GUICtrlSetData($tlabel, $val)
            WinSetTrans($optionsGUI,"",$val)
            Sleep(666)
            WinSetTrans($optionsGUI,"",255)
        Case $GUI_EVENT_CLOSE
            GUISetState(@SW_HIDE, $optionsGUI)
    EndSwitch
WEnd

Func TapTimer()
    $TapCount += 1
    Sleep(500)
    Switch $TapCount
    Case 2
        GUISetState(@SW_SHOW, $optionsGUI)
        WinSetOnTop($optionsGUI, "", 1)
        WinSetTrans($optionsGUI, "", 255)
        $TapCount = 0
    Case 1
        OnTop()
        $TapCount = 0
    Case Else
        GUISetState(@SW_SHOW, $optionsGUI)
        WinSetOnTop($optionsGUI, "", 1)
        WinSetTrans($optionsGUI, "", 255)
        $TapCount = 0
    EndSwitch
EndFunc   ;==>TapTimer

Func OnTop()
    If $Toggle = 0 Then
        $Toggle = 1
        Set()
    Else
        $Toggle = 0
        Unset()
    EndIf
EndFunc   ;==>OnTop

Func Set()
    $WinTitle = WinGetTitle("[active]")
    WinSetOnTop($WinTitle, "", 1)
    WinSetTrans($WinTitle, "", $val)
EndFunc   ;==>Set

Func Unset()
    $WinTitle = WinGetTitle("[active]")
    WinSetOnTop($WinTitle, "", 0)
    WinSetTrans($WinTitle, "", 255)
EndFunc   ;==>Unset

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  
Followers 0

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning guys
      I was trying to not open another post, writing here my little issue, but seems that no one cares about, and so, I'm opening another post
      What I'm trying to do, is detect the event close sent from the virtual keyboard.
      Why?
      Because, I have an application which, when I set the focus on a textbox, if the virtual keyboard does not exist, then it is created, else, it's not created
      But, everytime I try to close the virtual keyboard, the focus remains on the textbox, and another $EN_FOCUS event it's launched and detected from my WM_COMMAND, and so, the virtual keyboard is opened again. 
      How can I solve this little "issue"? 
      I was trying to detect the event sent from the virtual keyboard, storing the handle of it in a variable, and setting:
      GUISetOnEvent($GUI_EVENT_CLOSE, "CloseVK", $hVirtualKeyboard) without any result.
      Can someone please help me?
      Thanks  
      EDIT:
      Here I'd like to see @Melba23, @water, @Danyfirex...
       
    • LWC
      By LWC
      I've made a program that relies on IniReadSectionNames. It reads (~3K) Autorun.inf files in the working folder and creates a GUI based on their contents.
      I made sure to revert to a default GUI upon @error.
      But someone (with Windows XP SP3 32-bit) reported to me he always gets the default menu.
      I sent him a FileRead command instead and it works! So seemingly there's no access problem to AutoRun.inf.
      In the following demo code, I always hit success, but he always ends up with semi-success:
      Local $hIniLocation = "Autorun.inf" Local $aSections = IniReadSectionNames($hIniLocation) If @error Then $aSections = FileRead($hIniLocation) if @error then msgbox(48, "Double error", "Alternative access failed too due to:" & @crlf & @error & @crlf & @extended) else msgbox(0, "Semi-success", "IniReadSectionNames failed, but alternativaly this file contains:" & @crlf & @crlf & $aSections) endif else msgbox(0, "Success", "IniReadSectionNames worked!") endif Why is that? Is there something further to check with him?
      Autorun.inf
    • zetaimmersion
      By zetaimmersion
      I have 2 items (a field box and a bypass checkbox). every time the box is checked i need the field to become writable. unchecked is read only displaying some text.
      this is as far as i got as I am stuck at making it read/write toggle
      #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("Test", 500, 500) Global $hCombo = GUICtrlCreateInput("", 10, 10, 200, 20, BitOR($ES_AUTOHSCROLL,$ES_READONLY)) GUICtrlSetBkColor($hCombo,0xe7e5e5) Global $cbox = GUICtrlCreateCheckbox ("", 40,50,10,20) GUICtrlSetState($cbox, $GUI_Unchecked) GUISetState() Global $sCurrCombo = "" While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cbox If GUICtrlRead($cbox) <> $sCurrCombo Then $sCurrCombo = GUICtrlRead($cbox) GUICtrlSetStyle ($hCombo, $SS_LEFTNOWORDWRAP) GUICtrlSetBkColor($hCombo,0xFFFFFF) MsgBox(0, "Choice", "PLease enter the text") EndIf EndSwitch WEnd  
    • dascondor
      By dascondor
      So I having issues with this GUI/Listview. My main GUI works like it needs to but the ListView GUIs don't. The exit buttons do not work on them and om have a hard time getting them to work. And I'm trying to make the  listview GUI resizeable. But I'm not sure how to fix either of these issues any thoughts.
      #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <ScreenCapture.au3> #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <ListviewConstants.au3> #include 'MultiPing.au3' Opt("GUIOnEventMode", 1) #Region ;Declares ; Reads text file for the base list of IP's Global $aBase_IPlist = _FileReadToArray_mod(".\IP_List.txt") Global $replace2 = "Second" Global $replace3 = "Thrid" ;Global $userdata1 = GUICtrlRead($data1) ;Global $userdata2 = GUICtrlRead($data2) Global $savefolder = "C:\Users\" Global $paths = "\Desktop\PingChecks" Global $1stpaths = "\~~~Store" Global $2ndpaths = "~~~" Global $results = FileExists($savefolder & @UserName & $paths) ;Global $foldercheck = FileExists($savefolder & @UserName & $paths & $1stpaths & $userdata1 & $userdata2 & $2ndpaths) ;Global $savefile = "C:\Users\" & @UserName & "\Desktop\PingChecks\~~~Store" & $userdata1 & $userdata2 & "~~~\" #EndRegion ;Declares #Region ### START Koda GUI section ### Form= $IPMonkey = GUICreate("IP Monkey", 573, 254, -1, -1) GUISetIcon("C:\Users\Dlex\Pictures\monkeyicon.ico", -1) GUISetFont(16, 800, 0, "Arial") GUISetBkColor(0xFFFFFF) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_MAXIMIZE, "SpecialEvents") GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents") $data1 = GUICtrlCreateInput("1", 184, 120, 89, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetColor(-1, 0x000000) $data2 = GUICtrlCreateInput("23", 280, 120, 89, 32, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetColor(-1, 0x000000) $GOButton = GUICtrlCreateButton("GO", 80, 192, 75, 25) GUICtrlSetFont(-1, 10, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0x00FF00) GUICtrlSetTip(-1, "Runs A Live Continuous Ping" & @CRLF & _ "Until Told Other Wise") GUICtrlSetOnEvent(-1, "GOButtonClick") $quickscan = GUICtrlCreateButton("Quick Scan", 224, 192, 107, 25) GUICtrlSetFont(-1, 12, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFFFF00) GUICtrlSetOnEvent(-1, "quickscanClick") GUICtrlSetTip(-1, "Quickly Scans, Then Saves" & @CRLF & _ "Results In Your 'PingChecks' " & @CRLF & _ "Folder Under Your Store Number Folder") Global $exitbutton = GUICtrlCreateButton("Exit", 416, 192, 75, 25) GUICtrlSetFont(-1, 12, 800, 0, "Arial") GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFF0000) GUICtrlSetTip(-1, "What Do You Think This Button Does?") GUICtrlSetOnEvent(-1, "exitbuttonClick") $titlebar = GUICtrlCreateLabel("IP Monkey", 16, 120, 107, 28) GUICtrlSetColor(-1, 0x000000) $Pic1 = GUICtrlCreatePic("C:\Users\Dlex\Pictures\monkeyicon-0.jpg", 16, 16, 100, 100) GUICtrlSetOnEvent(-1, "Pic1Click") $infobutton = GUICtrlCreateButton("?", 536, 8, 27, 25) GUICtrlSetColor(-1, 0x000000) GUICtrlSetBkColor(-1, 0xFF8000) GUICtrlSetTip(-1, "Unsure what to do?" & @CRLF & _ "This will get give you " & @CRLF & _ "the help for IP Monkey") GUICtrlSetOnEvent(-1, "infobuttonClick") $Whatstorelabel = GUICtrlCreateLabel("What Store?", 208, 56, 130, 28) GUICtrlSetColor(-1, 0x000000) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #Region ;ping gui ; ------ pinger GUI ------------------- Global $StopPing = 0 Local $Win_X = 1200, $Win_Y = 880 ; dimension of window Global $PingGui = GUICreate("IP Monkey", $Win_X, $Win_Y, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents") Global $listview = GUICtrlCreateListView("", 10, 10, $Win_X - 20, $Win_Y - 40) GUICtrlSetFont(-1, 8) $button1 = GUICtrlCreateLabel("Hit Exit To Quit", 10, $Win_Y - 25, $Win_X - 20, 20, -1,$ES_CENTER) GUICtrlSetFont(-1, 10, 800) GUICtrlSetTip(-1, "exit") GUICtrlSetOnEvent(-1, 'SpecialEvents') GUICtrlSetStyle($listview, $LVS_ICON) ; + $LVS_NOLABELWRAP) GUISetState(@SW_HIDE) ; hidden at startup ; --------- end of pinger gui ------------- #EndRegion ;ping gui ; Generate colored square images $hImage = _GUIImageList_Create(30, 30) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFFFF00, 30, 30)) ; yellow _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFF0000, 30, 30)) ; red _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x00FF00, 30, 30)) ; green _GUICtrlListView_SetImageList($listview, $hImage, 0) While 1 Sleep(100) WEnd Func exitbuttonClick() MsgBox(0,'0','0') Exit EndFunc ;==>exitbuttonClick Func GOButtonClick() $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) ; pass the wanted new octet replace_And_Go($userdata1, $userdata2) ; generate a list of new IP and Go EndFunc ;==>GOButtonClick Func infobuttonClick() EndFunc ;==>infobuttonClick Func Pic1Click() EndFunc ;==>Pic1Click Func quickscanClick() $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) replace_And_Go2($userdata1, $userdata2) EndFunc ;==>quickscanClick Func SpecialEvents() Select Case @GUI_CtrlId = $GUI_EVENT_CLOSE _button1() Case @GUI_CtrlId = $GUI_EVENT_MINIMIZE Case @GUI_CtrlId = $GUI_EVENT_RESTORE Case @GUI_CtrlId = $GUI_EVENT_MAXIMIZE EndSelect EndFunc ;==>SpecialEvents #Region ; Main_GO/Replace_and_GO #cs ############################## second script ############################################# ; this is to ping continuously a list of IP addresses, get and display ping result "live" ; it simulates the dos "ping -t" command but performed simultaneously on many IP ; presenting the results in a ListView highlighting not responding devices with a red box #ce Func replace_And_Go($s_2, $s_3) ; Create a new array wit a new list of IP according to passed second and third octet Local $aNew_IPlist = $aBase_IPlist For $i = 0 To UBound($aNew_IPlist) - 1 $aNew_IPlist[$i][1] = StringReplace(StringReplace($aBase_IPlist[$i][1], $replace2, $s_2), $replace3, $s_3) Next GUISetState(@SW_HIDE, $IPMonkey) GUISetState(@SW_SHOW, $PingGui) ; pass the new list to the pinger Main_GO($aNew_IPlist) GUISetState(@SW_HIDE, $PingGui) GUISetState(@SW_SHOW, $IPMonkey) EndFunc ;==>replace_And_Go Func Main_GO($IPlist) HotKeySet("{esc}", "exitbuttonClick") $StopPing = 0 ; $IPlist = _FileReadToArray_mod(".\IP_List.txt") ; Reads text file for list of IP's ; ; the above command, it loads in the $IPlist array the values contained in the file IP_List.txt ; values in the file should be separated by a semicolon, something like in the following example: ; ; hostname1;192.168.0.1 ; hostname2;192.168.0.5 ; hostnameX;10.59.7.200 ; etc.... ; ; if values in the file are not separated by a semicolon, but another char is used, for example a comma, ; then just pass it as second parameter of the function: $IPlist = _FileReadToArray_mod(".\IP_List.txt", ",") ; _GUICtrlListView_BeginUpdate($listview) _GUICtrlListView_DeleteAllItems($listview) _GUICtrlListView_AddArray($listview, $IPlist) ; fill ListView _GUICtrlListView_EndUpdate($listview) While Not $StopPing ; 1 ; continuously ping addresses of the previously loaded file (IP_List.txt) Sleep(10) ; ; $IPlist is the array loaded with all the IP to be pinged (a 2d array in this case) ; | ; | 1 means the IP are in the second column of the $IPlist array (first colun is nr. 0) ; | | ; | | +--> 0 means return back an array loaded with results from all pinged addresses (responding and not responding) ; | | | if you use 1 then only responding addresses are loaded in the returned array [default] ; | | | if you use 2 then only NOT responding addresses are loaded in the returned array ; | | | In this case we do not need an array to be returned, we only need to perform all pings and pass results ; | | | directly (on the fly) to the "_refresh" callback function that will refresh the listview ; | | | ; | | | 0 means NO lookup name resolution must be performed ; | | | | ; | | | | +--> this is the callback function to be called for each pinged address each time the ping has finished ; | | | | | (see the MultiPing.au3 file for info on all passed params) ; | | | | | 6 parameters are passed to this function, but only 2 are used by the called function in this case: ; | | | | | [4] roundtrip of the responding ping or -1 if IP is down ; | | | | | [5] Index (position) of this IP within the caller's passed array ; | | | | | ; v v v v v _nPing($IPlist, 1, 0, 0, "_refresh") WEnd EndFunc ;==>Main_GO #EndRegion ; Main_GO/Replace_and_GO #Region ; QuickScan/Replace_and_GO2 Func replace_And_Go2($s_2, $s_3) ; Create a new array wit a new list of IP according to passed second and third octet Local $aNew_IPlist = $aBase_IPlist For $i = 0 To UBound($aNew_IPlist) - 1 $aNew_IPlist[$i][1] = StringReplace(StringReplace($aBase_IPlist[$i][1], $replace2, $s_2), $replace3, $s_3) Next GUISetState(@SW_HIDE, $IPMonkey) GUISetState(@SW_SHOW, $PingGui) ; pass the new list to the pinger QuickRun($aNew_IPlist) GUISetState(@SW_HIDE, $PingGui) GUISetState(@SW_SHOW, $IPMonkey) EndFunc ;==>replace_And_Go2 Func QuickRun($IPlist) $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) HotKeySet("{esc}", "_button1") Local $Win_X = 1200, $Win_Y = 880 ; dimension of window $PingGui = GUICreate("IP Monkey" & "~~~" & @UserName & "~~~" & "Store" & $userdata1 & $userdata2 & "~~~" & @MON & "." & @MDAY & "." & @YEAR & "~~~" & @HOUR & "." & @MIN, $Win_X, $Win_Y, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "_button1", $PingGui) $listview = GUICtrlCreateListView("", 10, 10, $Win_X - 20, $Win_Y - 40) GUICtrlSetFont(-1, 8) GUICtrlSetStyle($listview, $LVS_ICON) ; + $LVS_NOLABELWRAP) ; Generate colored square images $hImage = _GUIImageList_Create(30, 30) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFFFF00, 30, 30)) ; yellow _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0xFF0000, 30, 30)) ; red _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($listview, 0x00FF00, 30, 30)) ; green _GUICtrlListView_SetImageList($listview, $hImage, 0) $button1 = GUICtrlCreateButton("Exit", 10, $Win_Y - 25, $Win_X - 20, 20) GUICtrlSetTip(-1, "End of program") GUICtrlSetOnEvent(-1, "exitbuttonClick") GUISetState(@SW_SHOW) ;~ $IPlist = _FileReadToArray_mod(".\IP_List.txt") ; Reads text file for list of IP's _GUICtrlListView_BeginUpdate($listview) _GUICtrlListView_AddArray($listview, $IPlist) ; fill ListView _GUICtrlListView_EndUpdate($listview) ;While 1 ; perform Pings and update ListView by the "_refresh" callback function $aFinalResult = _nPing($IPlist, 1, 0, 0, "_refresh") ;~ _ArrayDisplay($aFinalResult) ;DirCheck() EndFunc ;==>QuickRun #EndRegion ; QuickScan/Replace_and_GO2 #Region ; Misc Funcs (network) Func _refresh($Params) ; this receive ping results and displays them in the ListView _GUICtrlListView_SetItemImage($listview, $Params[5], 0) ; set colour to Yellow Sleep(50) ; a little wait If $Params[4] = -1 Then ; Device not responding to ping _GUICtrlListView_SetItemImage($listview, $Params[5], 1) ; set colour to RED _GUICtrlListView_EnsureVisible($listview, $Params[5]) ; Position view to this item Else ; Device responds to ping _GUICtrlListView_SetItemImage($listview, $Params[5], 2) ; set colour to GREEN EndIf EndFunc ;==>_refresh Func _button1() ; Button 1 clicked ;~ $StopPing = 1 Exit EndFunc ;==>_button1 #EndRegion ; Misc Funcs (network)  
      MultiPing.au3
      IP_List.txt
    • jannikrendl
      By jannikrendl
      Hey,
      I'd like to create a gui wich records the total runtime of the script. 
      It should tell the hours,minutes and seconds (like this: Running since 00:00:00)
      This is what I have right now:
      Local $iTimer, $hGUI, $cLabel $iTimer = TimerInit() $hGUI = GUICreate("") $cLabel = GUICtrlCreateLabel("",300,380,100,20) GUISetState() AdlibRegister("_UpdateLabel",1000) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case -3 Exit EndSwitch Wend Func _UpdateLabel() $iTimerDiff = TimerDiff($iTimer) GUICtrlSetData($cLabel,"Running Since " & Round($iTimerDiff/1000,0) & " sec.") EndFunc Thanks in advance