Jump to content

Cancel (Abort Program)


gfunk999
 Share

Recommended Posts

Hey all,

Does anyone know why my stop button won't abort the script when my application is running? My application takes about 30 minutes to complete, and I would like to be able to abort, but once I launch it the stop and close button become useless.

thanks,

Gary

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <constants.au3>
#include <GuiStatusBar.au3>

$GUI = GUICreate("Marquee Progress Bar", 400, 100)

$status = GUICtrlCreateLabel("Status:", 50, 50, 93, 20)
             GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$l         = GUICtrlCreateLabel("", 100, 51, 400, 20)
                    
$GUI_Button = GUICtrlCreateButton("Run", 50, 70, 30, 20)
$GUI_Button1 = GUICtrlCreateButton("Stop", 100, 70, 30, 20)


GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_Button
            _prog()
        Case $GUI_Button1
            _prog1()
    EndSwitch
WEnd

Func _prog()
    
    $hp = _UpdateProgbar()
    GUICtrlSetData($l,"Running...")
    SBOnOff($hp,True)
    GUICtrlSetState(-1, $GUI_SHOW)
    MsgBox(0,"","stop for testing")
    ; this is where my applicaton will run for about 30 minutes, I would like to be able to abort
    GUICtrlSetData($l,"Now stopped")
    SBOnOff($hp,False)
    GUICtrlSetState(-1, $GUI_HIDE)
    
EndFunc

Func _prog1()
    
    Exit

EndFunc

Func _UpdateProgbar($hSb=0)
    
    Local $pbStyle = $PBS_MARQUEE,$hpb
    
    $progress = GUICtrlCreateProgress(50, 40, 200, 10, $pbStyle)

    $hpb = GUICtrlGetHandle($progress)
    
    If $hSb <> 0 then _GUICtrlStatusBar_EmbedControl($hSb, 2, $hpb)

    return $hpb
EndFunc

Func SBOnOff($bar, $onoff)
    
    _SendMessage($bar, $PBM_SETMARQUEE, $onoff, 40)
    
EndFunc
Link to comment
Share on other sites

the application i'm using is dsquery.exe, once launch it can take serveral minutes to complete. If I try if statements using a loop things get ugly. Basically, I have to wait until dsquery.exe is done before I can end the script. So i'm not sure if there's away to abort the script while dsquery is running...

What kind of functions are you using between 30 mins.? Loops?

Because, between these processes you could check in certain short time, if "Close" button was pressed.

Edited by gfunk999
Link to comment
Share on other sites

Ok guys,

This is the best I could come up with...adding an abort ESC key function worked, but it would be nice to have an abort button, but by the looks of it it may not be possible with AutoIT.

#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <constants.au3>
#include <GuiStatusBar.au3>

dim $hp, $set1

HotKeySet( "{esc}", "Abort" )

$GUI = GUICreate("Marquee Progress Bar", 400, 100)

$status = GUICtrlCreateLabel("Status:", 50, 50, 93, 20)
             GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
$l         = GUICtrlCreateLabel("", 100, 51, 400, 20)
                    
$GUI_Button = GUICtrlCreateButton("Run", 50, 70, 30, 20)
$GUI_Button1 = GUICtrlCreateButton("Stop", 100, 70, 30, 20)


GUISetState()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_Button
            _prog()
        Case $GUI_Button1
            _prog1()
    EndSwitch
WEnd

Func _prog()

    $hp = _UpdateProgbar()
    GUICtrlSetData($l,"Running...")
    SBOnOff($hp,True)
    GUICtrlSetState(-1, $GUI_SHOW)
    Sleep(5000)
            MsgBox(0, "test", $set1)
        If $set1 = "1" Then
            Return
        EndIf
    GUICtrlSetData($l,"Now stopped")
    SBOnOff($hp,False)
    GUICtrlSetState(-1, $GUI_HIDE)
    
EndFunc

Func Abort( )
            ProcessClose("dsquery.exe")
            GUICtrlSetData($l,"Stopped")
            SBOnOff($hp,False)
            GUICtrlSetState(-1, $GUI_HIDE)
            $set1 = "1"
            return          
EndFunc


Func _prog1()
    
    Exit

EndFunc

Func _UpdateProgbar($hSb=0)
    
    Local $pbStyle = $PBS_MARQUEE,$hpb
    
    $progress = GUICtrlCreateProgress(50, 40, 200, 10, $pbStyle)

    $hpb = GUICtrlGetHandle($progress)
    
    If $hSb <> 0 then _GUICtrlStatusBar_EmbedControl($hSb, 2, $hpb)

    return $hpb
EndFunc

Func SBOnOff($bar, $onoff)
    
    _SendMessage($bar, $PBM_SETMARQUEE, $onoff, 40)
    
EndFunc
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...