Jump to content

Recommended Posts

Posted

My shutdown timer has all the GUI controls. I haven't coded the minutes and hours portion of the program, but It seems Ok.

My problem is when I use the timer, I can't click on the stop button to deactivate the timer. Does anyone know how I can fix this? Here is the code. Feel free to correct any other flaws you might spot.

#NoTrayIcon

#include <e:\documents\autoit3\include\GUIConstants.au3>

#include <e:\documents\autoit3\include\String.au3>

SplashImageOn("","e:\documents\splash.bmp", 297, 137, -1, -1, 1)

sleep(2000)

SplashOff()

$window = GUICreate("Shutdown Timer... V.1.0", 172, 200, -1 ,-1, $WS_CAPTION)

$hours = GUICtrlCreateEdit("", 40, 10, 20, 20, $ES_NUMBER)

$minutes = GUICtrlCreateEdit("", 70, 10, 20, 20, $ES_NUMBER)

$seconds = GUICtrlCreateEdit("", 100, 10, 20, 20, $ES_NUMBER)

$secondstext = GUICtrlCreatelabel("sec", 100, 30, 20, 20)

$hourstext = GUICtrlCreatelabel("hrs", 40, 30, 20, 20)

$minstext = GUICtrlCreatelabel("min", 70, 30, 20, 20)

GUICtrlCreateLabel(":",63, 13, 3,20, 0)

GUICtrlCreateLabel(":",93, 13, 3,20, 0)

$startservice = GUICtrlCreateButton("&Start Service",40,50,80,25, -1)

$stopservice = GUICtrlCreateButton("S&top Service", 40,90, 80, 25, -1)

GUISetOnEvent(-1,"Stop")

$exit = GUICtrlCreateButton("&Exit", 40, 130, 80, 25, -1)

$newbutton = GUICtrlCreateButton("&Minimize", 40, 170, 80, 25, -1)

GUISetOnEvent(-1,"Minimize")

$icon = GUICtrlCreateIcon("e:\Visual_tools\icons\waitshutdown.ico",-1, 1, 1, $SS_ICON)

GUICtrlSetTip ( $exit, "Exits the timer service unloading it from memory" )

GUICtrlSetTip ( $startservice, "Starts the timer service" )

GUICtrlSetTip ( $stopservice, "Stops the timer service using a verified password." )

GUICtrlSetTip ( $newbutton, "Minimizes the timer service leaving it in memory" )

GUICtrlSetState($stopservice, $GUI_DISABLE)

Winsetstate("About","",@SW_HIDE)

GUIsetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $startservice

$readhours = GUICtrlRead($hours)

$readminutes = GUICtrlRead($minutes)

$readseconds = GUICtrlRead($seconds)

if $readseconds = 0 and $readhours = 0 and $readminutes = 0 then

msgbox(16,"Shutdown Timer...","You must enter a valid time.")

continueloop

elseif $readseconds = "" and $readhours = "" and $readminutes = "" then

msgbox(16,"Shutdown Timer...","You must enter a valid time.")

continueloop

elseif $readminutes > 59 or $readseconds > 59 then

msgbox(16,"Shutdown Timer...","Time is out of range. Time must be in 99:59:59 format

continueloop

endif

$startpassword = Inputbox("Shutdown Timer...","Enter a service password. This will prevent users from stopping the timer service.","","*",350,140)

$savedpassword = GUICtrlRead($startpassword)

if $startpassword = "" then

msgbox(16,"Shutdown Timer...","The password cannot be blank. Please enter a password")

continueloop

endif

$retype = Inputbox("Shutdown Timer...","Enter the password again for verification.","","*",350,140)

$readretype = GUICtrlRead($retype)

if $retype = $startpassword then

msgbox(64,"Shutdown Timer...","Password has been set")

else

msgbox(16,"Shutdown Timer...","The passwords don't match. Retype the passwords and try again.")

continueloop

endif

ControlDisable("","",$startservice)

ControlDisable("","",$exit)

GUICtrlSetState($stopservice, $GUI_ENABLE)

msgbox(48,"Shutdown Timer...","Time started: " & $readhours & " hrs" & " " & $readminutes & " " & " min" & " " & $readseconds & " " & " sec")

if $readseconds = 59 and $readhours = 0 and $readminutes = 0 then

msgbox(48,"Shutdown Timer...","1 minute remaining.")

elseif $readminutes = 1 and $readhours = 0 and $readseconds = 0 then

msgbox(48,"Shutdown Timer...","1 minute remaining.")

endif

WinSetState("", "",@SW_MINIMIZE)

timeme()

GUICtrlSetState($stopservice, $GUI_DISABLE)

GUICtrlSetState($startservice, $GUI_ENABLE)

GUICtrlSetState($exit, $GUI_ENABLE)

WinsetTitle("Shutdown Timer...","","Shutdown Timer... V.1.0")

continueloop

Case $msg = $newbutton

Minimize()

continueloop

Case $msg = $exit

exit

Case $msg = $stopservice

stop()

continueloop

Endselect

wend

Func Stop()

$stoppassword = Inputbox("Shutdown Timer...","Enter the service password to stop timer.","","*",350,140)

$verify = GUICtrlRead($stoppassword)

if $startpassword = $stoppassword then

ControlEnable("","",$startservice)

ControlDisable("","",$stopservice)

ControlEnable("","",$exit)

msgbox(64,"Shutdown Timer...","Timer service is inactive. To start timer press start service")

else

msgbox(16,"Shutdown Timer...","Invalid Service Password.")

endif

endfunc

Func Minimize()

WinSetState("", "",@SW_MINIMIZE)

endfunc

Func TimeMe()

$time = $readseconds

do

$time = $time - 1

WinsetTitle("Shutdown Timer...","","Shutdown Timer..." & $time)

sleep(1000)

until $time = 0

msgbox(48,"Shutdown Timer...","Time is up!")

GUICtrlSetState($stopservice, $GUI_DISABLE)

GUICtrlSetState($startservice, $GUI_ENABLE)

GUICtrlSetState($exit, $GUI_ENABLE)

WinsetTitle("Shutdown Timer...","","Shutdown Timer... V.1.0")

endfunc

Exit

F@m!ly Guy Fr33k! - Avatar speaks for itself__________________________________________________________________________________________ite quotes... - Is your refrigerator running? If it is, It probably runs like you...very homosexually - Christians don't believe in gravity - Geeze Brian where do you think you are, Payless?- Show me potato Salad!__________________________________________________________________________________________Programs available - Shutdown timer[indent][/indent]
Posted

My shutdown timer has all the GUI controls. I haven't coded the minutes and hours portion of the program, but It seems Ok.

My problem is when I use the timer, I can't click on the stop button to deactivate the timer. Does anyone know how I can fix this? Here is the code. Feel free to correct any other flaws you might spot.

#NoTrayIcon

#include <e:\documents\autoit3\include\GUIConstants.au3>

#include <e:\documents\autoit3\include\String.au3>

SplashImageOn("","e:\documents\splash.bmp", 297, 137, -1, -1, 1)

sleep(2000)

SplashOff()

$window = GUICreate("Shutdown Timer... V.1.0", 172, 200, -1 ,-1, $WS_CAPTION)

$hours = GUICtrlCreateEdit("", 40, 10, 20, 20, $ES_NUMBER)

$minutes = GUICtrlCreateEdit("", 70, 10, 20, 20, $ES_NUMBER)

$seconds = GUICtrlCreateEdit("", 100, 10, 20, 20, $ES_NUMBER)

$secondstext = GUICtrlCreatelabel("sec", 100, 30, 20, 20)

$hourstext = GUICtrlCreatelabel("hrs", 40, 30, 20, 20)

$minstext = GUICtrlCreatelabel("min", 70, 30, 20, 20)

GUICtrlCreateLabel(":",63, 13, 3,20, 0)

GUICtrlCreateLabel(":",93, 13, 3,20, 0)

$startservice = GUICtrlCreateButton("&Start Service",40,50,80,25, -1)

$stopservice = GUICtrlCreateButton("S&top Service", 40,90, 80, 25, -1)

GUISetOnEvent(-1,"Stop")

$exit = GUICtrlCreateButton("&Exit", 40, 130, 80, 25, -1)

$newbutton = GUICtrlCreateButton("&Minimize", 40, 170, 80, 25, -1)

GUISetOnEvent(-1,"Minimize")

$icon = GUICtrlCreateIcon("e:\Visual_tools\icons\waitshutdown.ico",-1, 1, 1, $SS_ICON)

GUICtrlSetTip ( $exit, "Exits the timer service unloading it from memory" )

GUICtrlSetTip ( $startservice, "Starts the timer service" )

GUICtrlSetTip ( $stopservice, "Stops the timer service using a verified password." )

GUICtrlSetTip ( $newbutton, "Minimizes the timer service leaving it in memory" )

GUICtrlSetState($stopservice, $GUI_DISABLE)

Winsetstate("About","",@SW_HIDE)

GUIsetState()

While 1

$msg = GUIGetMsg()

Select

Case $msg = $startservice

$readhours = GUICtrlRead($hours)

$readminutes = GUICtrlRead($minutes)

$readseconds = GUICtrlRead($seconds)

if $readseconds = 0 and $readhours = 0 and $readminutes = 0 then

msgbox(16,"Shutdown Timer...","You must enter a valid time.")

continueloop

elseif $readseconds = "" and $readhours = "" and $readminutes = "" then

msgbox(16,"Shutdown Timer...","You must enter a valid time.")

continueloop

elseif $readminutes > 59 or $readseconds > 59 then

msgbox(16,"Shutdown Timer...","Time is out of range. Time must be in 99:59:59 format

continueloop

endif

$startpassword = Inputbox("Shutdown Timer...","Enter a service password. This will prevent users from stopping the timer service.","","*",350,140)

$savedpassword = GUICtrlRead($startpassword)

if $startpassword = "" then

msgbox(16,"Shutdown Timer...","The password cannot be blank. Please enter a password")

continueloop

endif

$retype = Inputbox("Shutdown Timer...","Enter the password again for verification.","","*",350,140)

$readretype = GUICtrlRead($retype)

if $retype = $startpassword then

msgbox(64,"Shutdown Timer...","Password has been set")

else

msgbox(16,"Shutdown Timer...","The passwords don't match. Retype the passwords and try again.")

continueloop

endif

ControlDisable("","",$startservice)

ControlDisable("","",$exit)

GUICtrlSetState($stopservice, $GUI_ENABLE)

msgbox(48,"Shutdown Timer...","Time started: " & $readhours & " hrs" & " " & $readminutes & " " & " min" & " " & $readseconds & " " & " sec")

if $readseconds = 59 and $readhours = 0 and $readminutes = 0 then

msgbox(48,"Shutdown Timer...","1 minute remaining.")

elseif $readminutes = 1 and $readhours = 0 and $readseconds = 0 then

msgbox(48,"Shutdown Timer...","1 minute remaining.")

endif

WinSetState("", "",@SW_MINIMIZE)

timeme()

GUICtrlSetState($stopservice, $GUI_DISABLE)

GUICtrlSetState($startservice, $GUI_ENABLE)

GUICtrlSetState($exit, $GUI_ENABLE)

WinsetTitle("Shutdown Timer...","","Shutdown Timer... V.1.0")

continueloop

Case $msg = $newbutton

Minimize()

continueloop

Case $msg = $exit

exit

Case $msg = $stopservice

stop()

continueloop

Endselect

wend

Func Stop()

$stoppassword = Inputbox("Shutdown Timer...","Enter the service password to stop timer.","","*",350,140)

$verify = GUICtrlRead($stoppassword)

if $startpassword = $stoppassword then

ControlEnable("","",$startservice)

ControlDisable("","",$stopservice)

ControlEnable("","",$exit)

msgbox(64,"Shutdown Timer...","Timer service is inactive. To start timer press start service")

else

msgbox(16,"Shutdown Timer...","Invalid Service Password.")

endif

endfunc

Func Minimize()

WinSetState("", "",@SW_MINIMIZE)

endfunc

Func TimeMe()

$time = $readseconds

do

$time = $time - 1

WinsetTitle("Shutdown Timer...","","Shutdown Timer..." & $time)

sleep(1000)

until $time = 0

msgbox(48,"Shutdown Timer...","Time is up!")

GUICtrlSetState($stopservice, $GUI_DISABLE)

GUICtrlSetState($startservice, $GUI_ENABLE)

GUICtrlSetState($exit, $GUI_ENABLE)

WinsetTitle("Shutdown Timer...","","Shutdown Timer... V.1.0")

endfunc

Exit

about a month ago or so, someone made a script called 'eggtimer' i think, it has a series of tabs, each with 16 or so timers. you may want to search this forum for it. should give you some good ideas.
Posted

maybe this

Func TimeMe()
    $time = $readseconds
    $begin = TimerInit()
    Do
        $msg2 = GUIGetMsg()
        If $msg2 = $stopservice then ExitLoop
        $dif = TimerDiff($begin)
        If $dif >= 1000 Then
            $time = $time - 1
            WinSetTitle("Shutdown Timer...", "", "Shutdown Timer..." & $time)
            $begin = TimerInit()
        EndIf
    Until $time = 0
    MsgBox(48, "Shutdown Timer...", "Time is up!")
    GUICtrlSetState($stopservice, $GUI_DISABLE)
    GUICtrlSetState($startservice, $GUI_ENABLE)
    GUICtrlSetState($exit, $GUI_ENABLE)
    WinSetTitle("Shutdown Timer...", "", "Shutdown Timer... V.1.0")
EndFunc  ;==>TimeMe

8)

NEWHeader1.png

Posted

Thank you both very much cameronsdad and Valuater for your advice. Now on to coding the rest of the program...

:lmao:

F@m!ly Guy Fr33k! - Avatar speaks for itself__________________________________________________________________________________________ite quotes... - Is your refrigerator running? If it is, It probably runs like you...very homosexually - Christians don't believe in gravity - Geeze Brian where do you think you are, Payless?- Show me potato Salad!__________________________________________________________________________________________Programs available - Shutdown timer[indent][/indent]
Posted

i would also suggest, due to the many message boxes, that you set a time-out on them

example

msgbox(64,"Shutdown Timer...","Password has been set", 2)

waits two seconds then closes automatically

8)

NEWHeader1.png

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
×
×
  • Create New...