VenusProject2

GUI contaminated by closing child GUI

4 posts in this topic

#1 ·  Posted (edited)

Trying to isolate the cause of my parent GUI's graphic becoming contaminated by closing of a child GUI.

The example script below creates the parent GUI, then I click a button to display a digital clock, I use keys to start, pause & resume the clock. NOTE: to exit the clock display after the clock has started hold down the 'ESC' key for more than 3seconds. Upon the clock closing the contamination should be evident.

2016-03-08-GUI_Rubbish.jpg

 

#include <Misc.au3>
#include <GUIConstants.au3>
#include <Date.au3>

HotKeySet("{ESC}", "_ExitClock");To Exit Digital Clock use "Esc" key held for >3sec

Dim $aXY[2]
Global $Init0, $PausedTimer, $iTimerHours, $iTimerMins, $iTimerSecs
Global $sec = @SEC
Global $hDLL = DllOpen("user32.dll")
Global $iEvent = 0
Global $AlarmHour = 0
Global $AlarmMin = 0
Global $AlarmSec = 0
Global  $SecSquare = GUICtrlCreateGraphic(0, 0, 0, 0)
Global  $ClockSquare = GUICtrlCreateGraphic(5, 5, 180, 30);Local Time
Global  $TimerSquare = GUICtrlCreateGraphic(205, 5, 220, 30);Timer
Global $AlarmSquare = GUICtrlCreateGraphic(480, 5, 220, 30);Alarm Time
Global $gui
Dim $aDigChar[14]
_initDigChar($aDigChar)

; Create a GUI with various controls.
Local $Form1 = GUICreate("Example")

Local $StartB = GUICtrlCreateButton("Use 'Alt+S' to start Clock", 130, 200, 150, 25)
Local $PauseB = GUICtrlCreateButton("Use 'Alt+P' to pause Clock", 130, 250, 150, 25)
Local $ResumeB = GUICtrlCreateButton("Use 'Alt+R' to resume Clock", 130, 300, 150, 25)
GUICtrlSetState($StartB, $GUI_DISABLE)
GUICtrlSetState($PauseB, $GUI_DISABLE)
GUICtrlSetState($ResumeB, $GUI_DISABLE)

Local $OK = GUICtrlCreateButton("Display Clock", 270, 370, 125, 25)

; Display the GUI.
GUISetState(@SW_SHOW, $Form1)

; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $idOK
            ExitLoop
        Case $OK
            _DigitalClock()

    EndSwitch
WEnd

; Delete the previous GUI and all controls.
GUIDelete($Form1)


Func _DigitalClock()
    $gui = GUICreate("Digital Timer", 702, 40, -1, -1, -1, $WS_EX_TOPMOST)
    ;$gui = GUICreate("Test", 702, 702)
    GUISetBkColor(0x000000)

    GUISetState()


    $SecSquare = GUICtrlCreateGraphic(0, 0, 0, 0)
    $ClockSquare = GUICtrlCreateGraphic(5, 5, 180, 30);Local Time
    $TimerSquare = GUICtrlCreateGraphic(205, 5, 220, 30);Timer
    $AlarmSquare = GUICtrlCreateGraphic(480, 5, 220, 30);Alarm Time




    Dim $msg[1]
    ;$AddMinutes = 10
    While 1
        ; main loop, waits until @sec changes and then executes main drawing management function
        While @SEC = $sec
            $msg = GUIGetMsg(1)
            If $msg[0] = -3 Then
                DllClose($hDLL)
                Return
            EndIf
            If _IsPressed("12", $hDLL) Then;'Alt'
                ConsoleWrite("_IsPressed - Alt Key was pressed." & @CRLF)

                ; Wait until key is released.
                    While _IsPressed("12", $hDLL);
                        If _IsPressed("53",$hDLL) Then;'s'
                            ConsoleWrite("_IsPressed - 'o' Key was pressed." & @CRLF)

                            start_timer()
                        EndIf
                        If _IsPressed("50",$hDLL) Then;'p'
                            ConsoleWrite("_IsPressed - 'p' Key was pressed." & @CRLF)
                            pause_timer()
                        EndIf
                        If _IsPressed("52",$hDLL) Then;'r'
                            ConsoleWrite("_IsPressed - 'r' Key was pressed." & @CRLF)
                            resume_timer()
                        EndIf
                        Sleep(300);(250)
                    WEnd
            ElseIf _IsPressed("1B", $hDLL) Then
                MsgBox($MB_SYSTEMMODAL, "_IsPressed", "The Esc Key was pressed, therefore we will close the application.")
                ExitLoop
            EndIf

            Sleep(10)

        WEnd

        _draw()
        Sleep(50)
        $sec = @SEC
    WEnd
EndFunc; ==> _DigitalCLock


Func _ExitClock();Press Escape key for >5sec
    Local $Count = 0
    If _IsPressed("1B",$hDLL) Then
        $Return = _KeyPressed("1B", $Count)
        ConsoleWrite("Escape Key Held for - " & $Return & "mS" & @CRLF)
        If $Return > 3000 Then
            DllClose($hDLL)
            AdlibUnRegister("show_timer")
            GUIDelete($gui)
            GUISetState(@SW_ENABLE, $Form1);enable parent GUI
            GUISetState(@SW_SHOW,$Form1)
        EndIf
    Endif
EndFunc;==>_ExitClock()

Func _KeyPressed($kp_Key, ByRef $kp_Count)
    $kp_Count += 1
    Local $kp_Timer = TimerInit()
    While _IsPressed("1B")
        Sleep(100)
    WEnd
    Return TimerDiff($kp_Timer)
EndFunc   ;==>_KeyPressed


;################ Functions from StopwatchUDF.au3 #####################
; The function that starts or resets the stopwatch
Func start_timer()
   HotKeySet("{NUMPADMULT}") ;disable resume timer
   HotKeySet("{NUMPADSUB}", "pause_timer") ;enable pause timer
   $PausedTimer = 0
   $Init0 = TimerInit()
   AdlibRegister("show_timer", 60)


EndFunc   ;==>start_timer

; The function that pauses the stopwatch
Func pause_timer()
   HotKeySet("{NUMPADSUB}") ;disable pause timer
   HotKeySet("{NUMPADMULT}", "resume_timer") ;enable resume timer
   $PausedTimer += Int(TimerDiff($Init0))
   AdlibUnRegister()
EndFunc   ;==>pause_timer

; The function that resumes the stopwatch
Func resume_timer()
   HotKeySet("{NUMPADMULT}") ;disable resume timer
   HotKeySet("{NUMPADSUB}", "pause_timer") ;enable pause timer
   $Init0 = TimerInit()
   AdlibRegister("show_timer", 60)
EndFunc   ;==>resume_timer

Func show_timer()     ; _TicksToTime to get hours, mins, seconds
   _TicksToTime(Int(TimerDiff($Init0) + $PausedTimer), $iTimerHours, $iTimerMins, $iTimerSecs)

   ;StringFormat to display the time as HH:MM:SS
   ;ToolTip("HH:MM:SS = " & StringFormat("%02i:%02i:%02i", $iHours, $iMins, $iSecs), 0, 0, "Timer")
EndFunc   ;==>show_timer

; Exit
Func Quit()
   Exit
EndFunc   ;==>Quit
;################ Functions from StopwatchUDF.au3 #####################

Func _draw($forceDraw = False)
    ; calculates angles for min/sec dials, manages execution of drawing routines
    Local $doDraw = False

    Sleep(25)
    ;_drawSec()
    _DrawClock()
    _DrawTimer();Digital Cue Timer 00:00:00
    _DrawAlarmTime($iEvent);Event no. in Sequence with Hints in test string
    GUICtrlSetGraphic($SecSquare, $GUI_GR_REFRESH)
EndFunc   ;==>_draw
;#cs
Func _DrawClock();Digital System Time
    ;return
    ; manages execution of write commands for HH MM SS characters
    GUICtrlDelete($ClockSquare)
    $ClockSquare = GUICtrlCreateGraphic(5, 5, 180, 30);5, 5, 200, 30
    _timeWrite(0, Int(@HOUR / 10), "regular", $ClockSquare);e.g. 1pm = 13 /10 =1
    _timeWrite(20, Mod(@HOUR, 10), "regular", $ClockSquare);e.g. 1pm = 13Mod10 = 1 with 3 remainder
    _timeWrite(50, Int(@MIN / 10), "regular", $ClockSquare)
    _timeWrite(70, Mod(@MIN, 10), "regular", $ClockSquare)
    _timeWrite(100, Int(@SEC / 10), "regular", $ClockSquare)
    _timeWrite(120, Mod(@SEC, 10), "regular", $ClockSquare)
EndFunc   ;==>_drawTime
;#ce
Func _DrawTimer();Digital Cue Timer 00:00:00
    ;return
    ; manages execution of write commands for HH MM SS characters
    GUICtrlDelete($TimerSquare)
    $TimerSquare = GUICtrlCreateGraphic(205, 5, 220, 30);Timer
    _timeWrite(0, 13, "Timer", $TimerSquare);C
    _timeWrite(20, 11, "Timer", $TimerSquare);L
    _timeWrite(50, 12, "Timer", $TimerSquare);-
    _timeWrite(80, Int($iTimerHours / 10), "Timer", $TimerSquare)
    _timeWrite(100, Mod($iTimerHours, 10), "Timer", $TimerSquare)
    _timeWrite(130, Int($iTimerMins / 10), "Timer", $TimerSquare)
    _timeWrite(150, Mod($iTimerMins, 10), "Timer", $TimerSquare)
    _timeWrite(180, Int($iTimerSecs / 10), "Timer", $TimerSquare)
    _timeWrite(200, Mod($iTimerSecs, 10), "Timer", $TimerSquare)

EndFunc   ;==>_drawTime
;#cs
Func _drawAlarmTime($iEvent);Digital Time
    ;Return
    ; manages execution of write commands for HH MM SS characters for the Alarm time
    GUICtrlDelete($AlarmSquare)
    $AlarmSquare = GUICtrlCreateGraphic(480, 5, 220, 30)
    _timeWrite(0, 10, "Alarm", $AlarmSquare);A
    _timeWrite(20, 11, "Alarm", $AlarmSquare);L
    _timeWrite(50, 12, "Alarm", $AlarmSquare);-
    _timeWrite(80, Int($AlarmHour / 10), "Alarm", $AlarmSquare)
    _timeWrite(100, Mod($AlarmHour, 10), "Alarm", $AlarmSquare)
    _timeWrite(130, Int($AlarmMin / 10), "Alarm", $AlarmSquare)
    _timeWrite(150, Mod($AlarmMin, 10), "Alarm", $AlarmSquare)
    _timeWrite(180, Int($AlarmSec / 10), "Alarm", $AlarmSquare)
    _timeWrite(200, Mod($AlarmSec, 10), "Alarm", $AlarmSquare)
EndFunc   ;==>_drawAlarmTime
;#ce
Func _timeWrite($pos, $num, $type, $graph) ; $type is "Regular" or "Alarm" or "Timer"
    ; manages coloring and writing of 7 segement LEDs for time writing

    _setColorAndPenForWrite(StringMid($aDigChar[$num], 1, 1), $type);0
    _line($graph, $pos + 5, 2, $pos + 3, 10)

    _setColorAndPenForWrite(StringMid($aDigChar[$num], 2, 1), $type);1
    _line($graph, $pos + 2, 14, $pos + 0, 22)

    _setColorAndPenForWrite(StringMid($aDigChar[$num], 3, 1), $type);2
    _line($graph, $pos + 5 + 2, 0, $pos + 5 + 8, 0)

    _setColorAndPenForWrite(StringMid($aDigChar[$num], 4, 1), $type);3
    _line($graph, $pos + 2 + 2, 12, $pos + 2 + 8, 12)

    _setColorAndPenForWrite(StringMid($aDigChar[$num], 5, 1), $type);4
    _line($graph, $pos + 2, 24, $pos + 8, 24)

    _setColorAndPenForWrite(StringMid($aDigChar[$num], 6, 1), $type);5
    _line($graph, $pos + 5 + 10, 2, $pos + 3 + 10, 10)

    _setColorAndPenForWrite(StringMid($aDigChar[$num], 7, 1), $type);6
    _line($graph, $pos + 2 + 10, 14, $pos + 10, 22)
EndFunc   ;==>_timeWrite

;#cs
Func _line($graph, $x1, $y1, $x2, $y2);Seven Segment Display
    ;Return
    ; draws line for time writing
    GUICtrlSetGraphic($graph, $GUI_GR_MOVE, $x1 + 2, $y1 + 2)
    GUICtrlSetGraphic($graph, $GUI_GR_LINE, $x2 + 2, $y2 + 2)
EndFunc   ;==>_line
;#ce
Func _setColorAndPenForWrite($char, $type)
    ; sets color and pen for next line in time writing, based on '0' or '1' in the DigChar array
    If $char = "1"  Then;7 Segment display ON=1 or OFF=0
        If $type = "Alarm"  Then
            GUICtrlSetGraphic($AlarmSquare, $GUI_GR_PENSIZE, 2)
            GUICtrlSetGraphic($AlarmSquare, $GUI_GR_COLOR, 0xCCCCCC, 0xCCCCCC)
        ElseIf $type = "Timer" Then
            GUICtrlSetGraphic($TimerSquare, $GUI_GR_PENSIZE, 2)
            GUICtrlSetGraphic($TimerSquare, $GUI_GR_COLOR, 0x00ff00, 0x00ff00);ct - Bright Green RGB
        Else
            GUICtrlSetGraphic($ClockSquare, $GUI_GR_PENSIZE, 2)
            GUICtrlSetGraphic($ClockSquare, $GUI_GR_COLOR, 0xEE0000, 0xEE0000)
        EndIf
    Else
        If $type = "Alarm"  Then
            GUICtrlSetGraphic($AlarmSquare, $GUI_GR_PENSIZE, 2)
            GUICtrlSetGraphic($AlarmSquare, $GUI_GR_COLOR, 0x222222, 0x222222)
        ElseIf $type = "Timer" Then;ct
            GUICtrlSetGraphic($TimerSquare, $GUI_GR_PENSIZE, 2)
            GUICtrlSetGraphic($TimerSquare, $GUI_GR_COLOR, 0x002200, 0x002200);ct - Lite Green RGB
        Else
            GUICtrlSetGraphic($ClockSquare, $GUI_GR_PENSIZE, 2)
            GUICtrlSetGraphic($ClockSquare, $GUI_GR_COLOR, 0x330000, 0x330000)
        EndIf
    EndIf
EndFunc   ;==>_setColorAndPenForWrite

Func _drawSec()
    Return
    ; draws circle seconds indicator
    $aXY = _getXY(@SEC, 240)
    GUICtrlDelete($SecSquare)
    $SecSquare = GUICtrlCreateGraphic(350 + $aXY[0] - 8, 350 + $aXY[1] - 8, 16, 16)
    GUICtrlSetGraphic($SecSquare, $GUI_GR_COLOR, 0x0000FF, 0x0000FF)
    GUICtrlSetGraphic($SecSquare, $GUI_GR_ELLIPSE, 0, 0, 16, 16)
EndFunc   ;==>_drawSec

Func _getXY($sec, $hypo)
    ; returns array with X,Y coordinates for the seconds points for $sec seconds, with $hypo(tenuse) distance from center
    Dim $result[2]
    Local $pi = 3.14159265358979
    Local $degToRad = $pi / 180
    Local $degrees = $sec * 6 - 90
    Local $x = Cos($degrees * $degToRad) * $hypo
    Local $y = Sin($degrees * $degToRad) * $hypo
    $result[0] = $x
    $result[1] = $y
    Return $result
EndFunc   ;==>_getXY


Func _initDigChar(ByRef $aDigChar)
    ; define leds for digital numbers: 1 or 0 for leds on/off in 7-led digital clock characters
    $aDigChar[0] = "1110111"
    $aDigChar[1] = "0000011"
    $aDigChar[2] = "0111110"
    $aDigChar[3] = "0011111"
    $aDigChar[4] = "1001011"
    $aDigChar[5] = "1011101"
    $aDigChar[6] = "1111101"
    $aDigChar[7] = "0010011"
    $aDigChar[8] = "1111111"
    $aDigChar[9] = "1011111"
    $aDigChar[10] = "1111011" ; A
    $aDigChar[11] = "1100100" ; L
    $aDigChar[12] = "0001000" ; -
    $aDigChar[13] = "1110100" ;C
EndFunc   ;==>_initDigChar

Any help appreciated

Thanks Chris

Edited by VenusProject2

Share this post


Link to post
Share on other sites



VenusProject2,

You were exiting the clock within the _ExitClock function which was called by a HotKey. This function deleted the clock GUI, but did not affect the loop inside the _DigitalClock function, so the _draw function was still called and, as the only GUI left was the main one, that is where the function drew the clock.

I suggest you use a flag to show when the clock has been killed in the HotKey function and look for that flag in the loop - like this:

#include <Misc.au3>
#include <GUIConstants.au3>
#include <Date.au3>

Opt("TrayIconDebug", 1)

Global $fClose = False

HotKeySet("{ESC}", "_ExitClock");To Exit Digital Clock use "Esc" key held for >3sec

Dim $aXY[2]
Global $Init0, $PausedTimer, $iTimerHours, $iTimerMins, $iTimerSecs
Global $sec = @SEC
Global $hDLL = DllOpen("user32.dll")
Global $iEvent = 0
Global $AlarmHour = 0
Global $AlarmMin = 0
Global $AlarmSec = 0
Global  $SecSquare = GUICtrlCreateGraphic(0, 0, 0, 0)
Global  $ClockSquare = GUICtrlCreateGraphic(5, 5, 180, 30);Local Time
Global  $TimerSquare = GUICtrlCreateGraphic(205, 5, 220, 30);Timer
Global $AlarmSquare = GUICtrlCreateGraphic(480, 5, 220, 30);Alarm Time
Global $gui
Dim $aDigChar[14]
_initDigChar($aDigChar)

; Create a GUI with various controls.
Local $Form1 = GUICreate("Example")

Local $StartB = GUICtrlCreateButton("Use 'Alt+S' to start Clock", 130, 200, 150, 25)
Local $PauseB = GUICtrlCreateButton("Use 'Alt+P' to pause Clock", 130, 250, 150, 25)
Local $ResumeB = GUICtrlCreateButton("Use 'Alt+R' to resume Clock", 130, 300, 150, 25)
GUICtrlSetState($StartB, $GUI_DISABLE)
GUICtrlSetState($PauseB, $GUI_DISABLE)
GUICtrlSetState($ResumeB, $GUI_DISABLE)

Local $OK = GUICtrlCreateButton("Display Clock", 270, 370, 125, 25)

; Display the GUI.
GUISetState(@SW_SHOW, $Form1)

; Loop until the user exits.
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE, $idOK
            ExitLoop
        Case $OK
            _DigitalClock()

    EndSwitch
WEnd

; Delete the previous GUI and all controls.
GUIDelete($Form1)


Func _DigitalClock()
    $gui = GUICreate("Digital Timer", 702, 40, -1, -1, -1, $WS_EX_TOPMOST)
    ;$gui = GUICreate("Test", 702, 702)
    GUISetBkColor(0x000000)

    GUISetState()


    $SecSquare = GUICtrlCreateGraphic(0, 0, 0, 0)
    $ClockSquare = GUICtrlCreateGraphic(5, 5, 180, 30);Local Time
    $TimerSquare = GUICtrlCreateGraphic(205, 5, 220, 30);Timer
    $AlarmSquare = GUICtrlCreateGraphic(480, 5, 220, 30);Alarm Time




    Dim $msg[1]
    ;$AddMinutes = 10
    While 1
        ; main loop, waits until @sec changes and then executes main drawing management function
        While @SEC = $sec
            $msg = GUIGetMsg(1)
            If $msg[0] = -3 Then
                DllClose($hDLL)
                Return
            EndIf
            If _IsPressed("12", $hDLL) Then;'Alt'
                ConsoleWrite("_IsPressed - Alt Key was pressed." & @CRLF)

                ; Wait until key is released.
                    While _IsPressed("12", $hDLL);
                        If _IsPressed("53",$hDLL) Then;'s'
                            ConsoleWrite("_IsPressed - 'o' Key was pressed." & @CRLF)

                            start_timer()
                        EndIf
                        If _IsPressed("50",$hDLL) Then;'p'
                            ConsoleWrite("_IsPressed - 'p' Key was pressed." & @CRLF)
                            pause_timer()
                        EndIf
                        If _IsPressed("52",$hDLL) Then;'r'
                            ConsoleWrite("_IsPressed - 'r' Key was pressed." & @CRLF)
                            resume_timer()
                        EndIf
                        Sleep(300);(250)
                    WEnd
            ElseIf _IsPressed("1B", $hDLL) Then
                MsgBox($MB_SYSTEMMODAL, "_IsPressed", "The Esc Key was pressed, therefore we will close the application.")
                ExitLoop
            EndIf

            Sleep(10)

        WEnd

        If $fClose Then
            $fClose = False
            AdlibUnRegister("show_timer")
            GUIDelete($gui)
            GUISetState(@SW_ENABLE, $Form1);enable parent GUI
            GUISetState(@SW_SHOW,$Form1)
            Return
        Else
            _draw()
            Sleep(50)
            $sec = @SEC
        EndIf
    WEnd
EndFunc; ==> _DigitalCLock


Func _ExitClock();Press Escape key for >5sec
    Local $Count = 0
    If _IsPressed("1B",$hDLL) Then
        $Return = _KeyPressed("1B", $Count)
        ConsoleWrite("Escape Key Held for - " & $Return & "mS" & @CRLF)
        If $Return > 3000 Then
            $fClose = True
        EndIf
    Endif
EndFunc;==>_ExitClock()

Func _KeyPressed($kp_Key, ByRef $kp_Count)
    $kp_Count += 1
    Local $kp_Timer = TimerInit()
    While _IsPressed("1B")
        Sleep(100)
    WEnd
    Return TimerDiff($kp_Timer)
EndFunc   ;==>_KeyPressed


;################ Functions from StopwatchUDF.au3 #####################
; The function that starts or resets the stopwatch
Func start_timer()
   HotKeySet("{NUMPADMULT}") ;disable resume timer
   HotKeySet("{NUMPADSUB}", "pause_timer") ;enable pause timer
   $PausedTimer = 0
   $Init0 = TimerInit()
   AdlibRegister("show_timer", 60)


EndFunc   ;==>start_timer

; The function that pauses the stopwatch
Func pause_timer()
   HotKeySet("{NUMPADSUB}") ;disable pause timer
   HotKeySet("{NUMPADMULT}", "resume_timer") ;enable resume timer
   $PausedTimer += Int(TimerDiff($Init0))
   AdlibUnRegister()
EndFunc   ;==>pause_timer

; The function that resumes the stopwatch
Func resume_timer()
   HotKeySet("{NUMPADMULT}") ;disable resume timer
   HotKeySet("{NUMPADSUB}", "pause_timer") ;enable pause timer
   $Init0 = TimerInit()
   AdlibRegister("show_timer", 60)
EndFunc   ;==>resume_timer

Func show_timer()     ; _TicksToTime to get hours, mins, seconds
   _TicksToTime(Int(TimerDiff($Init0) + $PausedTimer), $iTimerHours, $iTimerMins, $iTimerSecs)

   ;StringFormat to display the time as HH:MM:SS
   ;ToolTip("HH:MM:SS = " & StringFormat("%02i:%02i:%02i", $iHours, $iMins, $iSecs), 0, 0, "Timer")
EndFunc   ;==>show_timer

; Exit
Func Quit()
   Exit
EndFunc   ;==>Quit
;################ Functions from StopwatchUDF.au3 #####################

Func _draw($forceDraw = False)
    ; calculates angles for min/sec dials, manages execution of drawing routines
    Local $doDraw = False

    Sleep(25)
    ;_drawSec()
    _DrawClock()
    _DrawTimer();Digital Cue Timer 00:00:00
    _DrawAlarmTime($iEvent);Event no. in Sequence with Hints in test string
    GUICtrlSetGraphic($SecSquare, $GUI_GR_REFRESH)
EndFunc   ;==>_draw
;#cs
Func _DrawClock();Digital System Time
    ;return
    ; manages execution of write commands for HH MM SS characters
    GUICtrlDelete($ClockSquare)
    $ClockSquare = GUICtrlCreateGraphic(5, 5, 180, 30);5, 5, 200, 30
    _timeWrite(0, Int(@HOUR / 10), "regular", $ClockSquare);e.g. 1pm = 13 /10 =1
    _timeWrite(20, Mod(@HOUR, 10), "regular", $ClockSquare);e.g. 1pm = 13Mod10 = 1 with 3 remainder
    _timeWrite(50, Int(@MIN / 10), "regular", $ClockSquare)
    _timeWrite(70, Mod(@MIN, 10), "regular", $ClockSquare)
    _timeWrite(100, Int(@SEC / 10), "regular", $ClockSquare)
    _timeWrite(120, Mod(@SEC, 10), "regular", $ClockSquare)
EndFunc   ;==>_drawTime
;#ce
Func _DrawTimer();Digital Cue Timer 00:00:00
    ;return
    ; manages execution of write commands for HH MM SS characters
    GUICtrlDelete($TimerSquare)
    $TimerSquare = GUICtrlCreateGraphic(205, 5, 220, 30);Timer
    _timeWrite(0, 13, "Timer", $TimerSquare);C
    _timeWrite(20, 11, "Timer", $TimerSquare);L
    _timeWrite(50, 12, "Timer", $TimerSquare);-
    _timeWrite(80, Int($iTimerHours / 10), "Timer", $TimerSquare)
    _timeWrite(100, Mod($iTimerHours, 10), "Timer", $TimerSquare)
    _timeWrite(130, Int($iTimerMins / 10), "Timer", $TimerSquare)
    _timeWrite(150, Mod($iTimerMins, 10), "Timer", $TimerSquare)
    _timeWrite(180, Int($iTimerSecs / 10), "Timer", $TimerSquare)
    _timeWrite(200, Mod($iTimerSecs, 10), "Timer", $TimerSquare)

EndFunc   ;==>_drawTime
;#cs
Func _drawAlarmTime($iEvent);Digital Time
    ;Return
    ; manages execution of write commands for HH MM SS characters for the Alarm time
    GUICtrlDelete($AlarmSquare)
    $AlarmSquare = GUICtrlCreateGraphic(480, 5, 220, 30)
    _timeWrite(0, 10, "Alarm", $AlarmSquare);A
    _timeWrite(20, 11, "Alarm", $AlarmSquare);L
    _timeWrite(50, 12, "Alarm", $AlarmSquare);-
    _timeWrite(80, Int($AlarmHour / 10), "Alarm", $AlarmSquare)
    _timeWrite(100, Mod($AlarmHour, 10), "Alarm", $AlarmSquare)
    _timeWrite(130, Int($AlarmMin / 10), "Alarm", $AlarmSquare)
    _timeWrite(150, Mod($AlarmMin, 10), "Alarm", $AlarmSquare)
    _timeWrite(180, Int($AlarmSec / 10), "Alarm", $AlarmSquare)
    _timeWrite(200, Mod($AlarmSec, 10), "Alarm", $AlarmSquare)
EndFunc   ;==>_drawAlarmTime
;#ce
Func _timeWrite($pos, $num, $type, $graph) ; $type is "Regular" or "Alarm" or "Timer"
    ; manages coloring and writing of 7 segement LEDs for time writing

    _setColorAndPenForWrite(StringMid($aDigChar[$num], 1, 1), $type);0
    _line($graph, $pos + 5, 2, $pos + 3, 10)

    _setColorAndPenForWrite(StringMid($aDigChar[$num], 2, 1), $type);1
    _line($graph, $pos + 2, 14, $pos + 0, 22)

    _setColorAndPenForWrite(StringMid($aDigChar[$num], 3, 1), $type);2
    _line($graph, $pos + 5 + 2, 0, $pos + 5 + 8, 0)

    _setColorAndPenForWrite(StringMid($aDigChar[$num], 4, 1), $type);3
    _line($graph, $pos + 2 + 2, 12, $pos + 2 + 8, 12)

    _setColorAndPenForWrite(StringMid($aDigChar[$num], 5, 1), $type);4
    _line($graph, $pos + 2, 24, $pos + 8, 24)

    _setColorAndPenForWrite(StringMid($aDigChar[$num], 6, 1), $type);5
    _line($graph, $pos + 5 + 10, 2, $pos + 3 + 10, 10)

    _setColorAndPenForWrite(StringMid($aDigChar[$num], 7, 1), $type);6
    _line($graph, $pos + 2 + 10, 14, $pos + 10, 22)
EndFunc   ;==>_timeWrite

;#cs
Func _line($graph, $x1, $y1, $x2, $y2);Seven Segment Display
    ;Return
    ; draws line for time writing
    GUICtrlSetGraphic($graph, $GUI_GR_MOVE, $x1 + 2, $y1 + 2)
    GUICtrlSetGraphic($graph, $GUI_GR_LINE, $x2 + 2, $y2 + 2)
EndFunc   ;==>_line
;#ce
Func _setColorAndPenForWrite($char, $type)
    ; sets color and pen for next line in time writing, based on '0' or '1' in the DigChar array
    If $char = "1"  Then;7 Segment display ON=1 or OFF=0
        If $type = "Alarm"  Then
            GUICtrlSetGraphic($AlarmSquare, $GUI_GR_PENSIZE, 2)
            GUICtrlSetGraphic($AlarmSquare, $GUI_GR_COLOR, 0xCCCCCC, 0xCCCCCC)
        ElseIf $type = "Timer" Then
            GUICtrlSetGraphic($TimerSquare, $GUI_GR_PENSIZE, 2)
            GUICtrlSetGraphic($TimerSquare, $GUI_GR_COLOR, 0x00ff00, 0x00ff00);ct - Bright Green RGB
        Else
            GUICtrlSetGraphic($ClockSquare, $GUI_GR_PENSIZE, 2)
            GUICtrlSetGraphic($ClockSquare, $GUI_GR_COLOR, 0xEE0000, 0xEE0000)
        EndIf
    Else
        If $type = "Alarm"  Then
            GUICtrlSetGraphic($AlarmSquare, $GUI_GR_PENSIZE, 2)
            GUICtrlSetGraphic($AlarmSquare, $GUI_GR_COLOR, 0x222222, 0x222222)
        ElseIf $type = "Timer" Then;ct
            GUICtrlSetGraphic($TimerSquare, $GUI_GR_PENSIZE, 2)
            GUICtrlSetGraphic($TimerSquare, $GUI_GR_COLOR, 0x002200, 0x002200);ct - Lite Green RGB
        Else
            GUICtrlSetGraphic($ClockSquare, $GUI_GR_PENSIZE, 2)
            GUICtrlSetGraphic($ClockSquare, $GUI_GR_COLOR, 0x330000, 0x330000)
        EndIf
    EndIf
EndFunc   ;==>_setColorAndPenForWrite

Func _drawSec()
    Return
    ; draws circle seconds indicator
    $aXY = _getXY(@SEC, 240)
    GUICtrlDelete($SecSquare)
    $SecSquare = GUICtrlCreateGraphic(350 + $aXY[0] - 8, 350 + $aXY[1] - 8, 16, 16)
    GUICtrlSetGraphic($SecSquare, $GUI_GR_COLOR, 0x0000FF, 0x0000FF)
    GUICtrlSetGraphic($SecSquare, $GUI_GR_ELLIPSE, 0, 0, 16, 16)
EndFunc   ;==>_drawSec

Func _getXY($sec, $hypo)
    ; returns array with X,Y coordinates for the seconds points for $sec seconds, with $hypo(tenuse) distance from center
    Dim $result[2]
    Local $pi = 3.14159265358979
    Local $degToRad = $pi / 180
    Local $degrees = $sec * 6 - 90
    Local $x = Cos($degrees * $degToRad) * $hypo
    Local $y = Sin($degrees * $degToRad) * $hypo
    $result[0] = $x
    $result[1] = $y
    Return $result
EndFunc   ;==>_getXY


Func _initDigChar(ByRef $aDigChar)
    ; define leds for digital numbers: 1 or 0 for leds on/off in 7-led digital clock characters
    $aDigChar[0] = "1110111"
    $aDigChar[1] = "0000011"
    $aDigChar[2] = "0111110"
    $aDigChar[3] = "0011111"
    $aDigChar[4] = "1001011"
    $aDigChar[5] = "1011101"
    $aDigChar[6] = "1111101"
    $aDigChar[7] = "0010011"
    $aDigChar[8] = "1111111"
    $aDigChar[9] = "1011111"
    $aDigChar[10] = "1111011" ; A
    $aDigChar[11] = "1100100" ; L
    $aDigChar[12] = "0001000" ; -
    $aDigChar[13] = "1110100" ;C
EndFunc   ;==>_initDigChar

M23

1 person likes this

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

Melba it has been said by many before me, but I'm compelled to say it again, you're the Jedi of code possibly part Vulcan(adept logic)....lol Thanks Mate

Share this post


Link to post
Share on other sites

VenusProject2,

Glad I could help. Live long and prosper.

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

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

  • Similar Content

    • 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
    • dascondor
      By dascondor
      I  need to has Opt(GUISetOnEvent,-1) available in my script, but since I'm using koda designer it uses GUIgetmessage is there any work around for this. I'm pretty new to this stuff so any help is great appreciated.
      Any Thoughts?
       
    • dascondor
      By dascondor
      Hello I've been working on an IP Scanner Program with help from other people on the forum. Anyway I've hit a wall with why the GUI won't close on Exit button once pass the main screen, please if anyone could help that would be great.
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=..\..\..\Downloads\monkeyicon.ico #AutoIt3Wrapper_Outfile=IP Monkey.exe #AutoIt3Wrapper_Run_Tidy=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #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' ; <-- take this from the following link: ; http://www.autoitscript.com/forum/topic/156395-versatile-multi-ping #Region ;ping gui Opt("GUIOnEventMode", 1) ; ------ 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, "_button1", $PingGui) 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, 1, 800) ;~ GUICtrlSetTip(-1, "save") ;~ GUICtrlSetOnEvent(-1, 'QuickRun') 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) #Region ### START Koda GUI section ### Form= $IPpong = GUICreate("IP Monkey", 572, 253, -1, -1) GUISetBkColor(0xFFFFFF) Global $data1 = GUICtrlCreateInput("1", 184, 104, 81, 37, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x000000) Global $data2 = GUICtrlCreateInput("23", 280, 104, 73, 37, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER)) GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x000000) Global $gobutton = GUICtrlCreateButton("GO", 80, 192, 75, 25) GUICtrlSetTip(-1, "Runs A Live Continuous Ping" & @CRLF & _ "Until Told Other Wise") GUICtrlSetBkColor(-1, 0x00FF00) Global $quickbutton = GUICtrlCreateButton("Quick Run", 240, 192, 75, 25) GUICtrlSetTip(-1, "Quickly Scans, Then Saves" & @CRLF & _ "Results In Your 'PingChecks' " & @CRLF & _ "Folder Under Your Store Number Folder") GUICtrlSetBkColor(-1, 0xFFFF00) $title = GUICtrlCreateLabel("IP Monkey", 16, 128, 116, 33) GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x000000) $infobutton = GUICtrlCreateButton("?", 536, 16, 27, 25) GUICtrlSetTip(-1, "Unsure what to do?" & @CRLF & _ "This will get give you " & @CRLF & _ "the help for IP Monkey") GUICtrlSetBkColor(-1, 0xFF8000) ;$superbutton = GUICtrlCreateButton("", 0, 0, 19, 17) ;GUICtrlSetBkColor(-1, 0xFFFFFF) ;GUICtrlSetState(-1, $GUI_HIDE) $Label1 = GUICtrlCreateLabel("What Store?", 200, 40, 145, 33) GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x000000) Global $exitbutton = GUICtrlCreateButton("Exit", 400, 192, 75, 25) GUICtrlSetTip(-1, "What Do You Think This Button Does?") GUICtrlSetBkColor(-1, 0xFF0000) $Icon = GUICtrlCreatePic("C:\Users\" & @UserName & "\Desktop\monkeyicon-0.jpg", 16, 16, 100, 100) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### #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 ; Foldercreation/ScreenCap/HelpFile Func DirCheck() Global $savefolder = "C:\Users\" Global $paths = "\Desktop\PingChecks" $results = FileExists($savefolder & @UserName & $paths) Global $helptext = "C:\Users\" & @UserName & "\Desktop\PingChecks\README.txt" If $results = 0 Then DirCreate($savefolder & @UserName & $paths) FileWrite($helptext, " .. IMMMI .. " & @CRLF & _ " .~MMMMMMMMMMMMM~. ") Createdforstore() ElseIf $results = 1 Then Createdforstore() EndIf EndFunc ;==>DirCheck Func Createdforstore() Local $pathslocal = "\Desktop\PingChecks\" If $foldercheck = 0 Then DirCreate($savefolder & @UserName & $pathslocal & $1stpaths & $userdata1 & $userdata2 & $2ndpaths) Screencap() ElseIf $foldercheck = 1 Then Screencap() EndIf EndFunc ;==>Createdforstore Func Screencap() $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) Local $savesfile = "C:\Users\" & @UserName & "\Desktop\PingChecks\~~~Store" & $userdata1 & $userdata2 & "~~~\" Global $point = "," Global $time = "." Global $id = "Store" Global $tid = "~" ;~ Global $pathslocal = "\Desktop\PingChecks\" _ScreenCapture_CaptureWnd($savesfile & @UserName & $tid & $id & $userdata1 & $userdata2 & $tid & @MON & $time & @MDAY & $time & @YEAR & $tid & @HOUR & $time & @MIN & $tid & ".jpg", $PingGui) MsgBox(0, "Completed", " Your Ping Scan Is In Your PingChecks Folder, " & @CRLF & _ "On Your Desktop.") Exit EndFunc ;==>Screencap ;helpfile Func Helpfile() $readmecheck = FileExists("README.txt") If $readmecheck = 1 Then ShellExecute("README.txt") ElseIf $readmecheck = 0 Then Run("Notepad.exe") WinWait("Untitled - Notepad") ControlSetText("Untitled - Notepad", '', 'Edit1', " .. IMMMI .. " & @CRLF & _ " .~MMMMMMMMMMMMM~. ") EndIf EndFunc ;==>Helpfile #EndRegion ; Foldercreation/ScreenCap/HelpFile #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, $IPpong) GUISetState(@SW_SHOW, $PingGui) ; pass the new list to the pinger Main_GO($aNew_IPlist) GUISetState(@SW_HIDE, $PingGui) GUISetState(@SW_SHOW, $IPpong) EndFunc ;==>replace_And_Go Func Main_GO($IPlist) HotKeySet("{esc}", "_button1") ; $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 HotKeySet("{esc}", _button1) $StopPing = 0 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, $IPpong) GUISetState(@SW_SHOW, $PingGui) ; pass the new list to the pinger QuickRun($aNew_IPlist) GUISetState(@SW_HIDE, $PingGui) GUISetState(@SW_SHOW, $IPpong) 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, "_button1") 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) While (1) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $gobutton $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) ; pass the wanted new octet replace_And_Go($userdata1, $userdata2) ; generate a list of new IP and Go Case $infobutton Helpfile() ;Case $superbutton ;Run("notepad.exe") Case $quickbutton $userdata1 = GUICtrlRead($data1) $userdata2 = GUICtrlRead($data2) replace_And_Go2($userdata1, $userdata2) Case $exitbutton Exit EndSwitch WEnd