Jump to content

Cancellalbe Progress Bar


Recommended Posts

I made a simple progress bar by using ProgressOn() to display the deployment of network printers for a lab computer. The process of installing the drivers for each printer can take some time, so the whole process can take 2 minutes. The progress bar works perfectly, but I would like to give end user an option to cancel the whole task by closing the progress bar box. If a user never intends to print, but is checking facebook/email/class schedule between classes, there is no need to slow down the computer with loading of printer drivers... Is it possible to integrate a Cancel button into the Progress Bar?

Thanks,

RMSe17

Link to comment
Share on other sites

Create your own ProgressGui by using GUICtrlCreateProgress and you can put whatever buttons you like on it, see the example from helpfile.

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>

Opt('MustDeclareVars', 1)

Example()

Func Example()
    Local $progressbar1, $progressbar2, $button, $wait, $s, $msg, $m
    
    GUICreate("My GUI Progressbar", 220, 100, 100, 200)
    $progressbar1 = GUICtrlCreateProgress(10, 10, 200, 20)
    GUICtrlSetColor(-1, 32250); not working with Windows XP Style
    $progressbar2 = GUICtrlCreateProgress(10, 40, 200, 20, $PBS_SMOOTH)
    $button = GUICtrlCreateButton("Start", 75, 70, 70, 20)
    GUISetState()

    $wait = 20; wait 20ms for next progressstep
    $s = 0; progressbar-saveposition
    Do
        $msg = GUIGetMsg()
        If $msg = $button Then
            GUICtrlSetData($button, "Stop")
            For $i = $s To 100
                If GUICtrlRead($progressbar1) = 50 Then MsgBox(0, "Info", "The half is done...", 1)
                $m = GUIGetMsg()
                
                If $m = -3 Then ExitLoop
                
                If $m = $button Then
                    GUICtrlSetData($button, "Next")
                    $s = $i;save the current bar-position to $s
                    ExitLoop
                Else
                    $s = 0
                    GUICtrlSetData($progressbar1, $i)
                    GUICtrlSetData($progressbar2, (100 - $i))
                    Sleep($wait)
                EndIf
            Next
            If $i > 100 Then
                ;       $s=0
                GUICtrlSetData($button, "Start")
            EndIf
        EndIf
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example
GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.
Link to comment
Share on other sites

You can create your own progress window with a cancel button and have the button exit the script. Something like:

#include <ProgressConstants.au3>
#include <WindowsConstants.au3>
Opt("GuiOnEventMode", 1)

$guProg = GUICreate("Window", 300, 110, -1, -1, BitOR($WS_POPUP, $WS_CAPTION))
$lbMain = GUICtrlCreateLabel("main", 20, 5, 1280, 24)
GUICtrlSetFont(-1, 11, 800)
$pgMain = GUICtrlCreateProgress(20, 30, 260, 20, $PBS_SMOOTH)
$lbSubtext = GUICtrlCreateLabel("sub", 20, 55, 1280, 24)
GUICtrlCreateButton("Cancel", 205, 78, 75, 24)
GUICtrlSetOnEvent(-1, "_Exit")
GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd

Func _Exit()
    Exit
EndFunc

Of course, you would need to create some functions to update the progress as needed.

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...