Cancel button to stop a script?

Started by Ron47, April 02, 2020, 02:24:47 PM

Previous topic - Next topic

Ron47

I have a script that takes at least 15 seconds of processing time to start up. The script then opens a couple of programs.
At the end of the proccessing, I could display a dialog that lets the users cancel.
But, 15 wasted seconds can be annoying.
So, it'd be great if I could let the users cancel during the startup.


Currently I display a message during the startup that lets the users press the shift key to cancel
(I've interspersed the code with multiple IsKeyDown(@SHIFT) statements that cancel.)


BoxesUp("350,200,600,400",@normal)
BoxColor(1,"142,157,160",0)
BoxTextColor(1,"251,251,251")
BoxDrawRect( 1, "0,0,1000,1000", 2)
BoxTextFont(1, "helvetica", "100", "60", "32")
BoxDrawText(1, "0,310,1000,1000", "Opening - Please wait!",  @FALSE, 1)   
BoxTextFont(1, "helvetica", "90", "60", "32")
BoxDrawText(1, "0,600,1000,1000", "(Hold shift key to cancel)",  @FALSE, 1)
BoxCaption(1, "Dialog")

boxshut() ;;;;    at the end of the processing



But, this isn't a great solution and the users would prefer to have a Cancel button in the Dialog box.

Something like:
BoxButtonDraw(1, bDraw1, "Cancel", "400,600,550,750")

But,

BoxButtonWait()

stops the processing.


Any ideas?

Thanks!
Ron

Ron47

I figured it out. (by reading your documentation for BoxButtonStat - Thanks!!.)
Buttonclick cancels.


BoxesUp("100,100,900,900", @NORMAL)
BoxDrawText(1, "0,210,1000,1000", "WinBatch Box Example - BoxButtonDraw %@CRLF% Drawing Buttons", @FALSE, 1)
BoxButtonDraw(1, bbDraw1, "Button 1", "100,450,300,550")

bWho=0
While bWho == 0
      If BoxButtonStat(1,1) Then exit
       timedelay(3); processing
       If BoxButtonStat(1,1) Then exit
       timedelay(3) ; processing
      If BoxButtonStat(1,1) Then exit
       timedelay(3) ; processing
      If BoxButtonStat(1,1) Then exit
       timedelay(3); processing
      If BoxButtonStat(1,1) Then exit
       timedelay(3); processing

      break  ;;; finished processing
EndWhile
boxshut()
Message("","Continue...")
exit