Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: countdown timers
What I am trying to do is cause a delayed shutdown but keep the user apprised of how much time is left . Tried some of the timing functions but they were not able to update the screen rapidly enough. Would like this to countdown per second or two if possible.
I want to write a script to shutdown the computer but warn the user the remaining time before shutdown,a user can cancel the shut down or if no user intervi,the computer shuts down(win98,2000,XP)
Or...
Here's a generic countdown timer I wrote using the Box functions. It may not be as pretty as a dialog but may work better depending on what your're doing.;Thus DefineFunction may be used #DefineFunction DoItToIt(MyDialogHandle,MyDialogMessage,MyDialogControlID,param4,param5) InitDialog = 0 TimerTick = 1 Switch MyDialogMessage Case InitDialog ; Init_Dialog (case number 0 subject to change on implementation) DialogProcOptions(MyDialogHandle,TimerTick, 1000) ; enable 1 second timer events Return (-1) Case TimerTick Clock=DialogControlGet(MyDialogHandle, 3, 4) Clock=Clock-1 If Clock==0 Then Return(2) ; exit, buttonpushed==2 DialogControlSet(MyDialogHandle, 3, 4, Clock) Return(-1) EndSwitch ; MyDialogMessage Return(-1) ; Do default processing #EndFunction MyDialogFormat=`WWWDLGED,6.1` MyDialogCaption=`WIL Dialog 1` MyDialogX=78 MyDialogY=129 MyDialogWidth=121 MyDialogHeight=117 MyDialogNumControls=3 MyDialogFont=`DEFAULT` MyDialogTextColor=`DEFAULT` MyDialogBackground=`DEFAULT` MyDialogProcedure="DoItToIt" ;;;;;;;;;;;;;;;;added line MyDialog001=`12,82,35,14,PUSHBUTTON,DEFAULT,"OK",1,DEFAULT,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog002=`66,82,35,14,PUSHBUTTON,DEFAULT,"Cancel",0,DEFAULT,DEFAULT,DEFAULT,DEFAULT,DEFAULT` MyDialog003=`22,15,71,53,VARYTEXT,clock,"10",DEFAULT,DEFAULT,DEFAULT,"Tahoma|49152|70|34","128|0|0",DEFAULT` ButtonPushed=Dialog("MyDialog") Message("ButtonPushed Results",ButtonPushed) Exit ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
It displays both a countdown clock and a decrementing count of seconds. Use whichever you want.
You could check "secs" after the while loop is exited. If "secs" is zero it timed out, otherwise they pressed the button, whose text you could easily change to "Skip shutdown" or anything you want. You may have to resize the button.
;----------------------------------------------------------------------------------- :init btn = 0 starttime = timeymdhms() endtime = timeadd(starttime,"00:00:00:00:00:3600") LTGRAY="192,192,192" BLACK="0,0,0" ;----------------------------------------------------------------------------------- :main wbid = 1 BoxesUp("100,300,500,600",@normal) BoxCaption(wbid,"Countdown Timer") BoxColor(wbid,LTGRAY,0) BoxDrawRect(wbid,"0,0,1000,1000",2) BoxTextFont(wbid,"Arial",70,60,0) BoxTextColor(wbid,BLACK) BoxDrawText(wbid,"5,5,1000,1000",starttime,1,0) BoxButtonDraw(wbid,1,"Exit now","25,875,200,975") BoxDataTag(wbid,"here") ; to control the stack while !btn btn = BoxButtonStat(1,1) Timedelay(.1) now = timeymdhms() secs = timediffsecs(endtime,now) diff = timediff(endtime,now) BoxDrawText(wbid,"70,500,1000,1000",diff,1,0) BoxDrawText(wbid,"700,875,1000,1000",secs,1,0) if secs == 0 then break if secs mod 10 == 0 then boxdataclear(wbid,"here") ; don't let the stack overflow! endwhile boxdestroy(wbid) ;message("Timeout",btn) ;----------------------------------------------------------------------------------- :alldone ;----------------------------------------------------------------------------------- :END exit
Article ID: W15723
File Created: 2003:05:28:10:23:36
Last Updated: 2003:05:28:10:23:36