Jump to content

_ProgressSetMarquee() - Starts/Stops the $PBS_MARQUEE style on a ProgressBar.


Recommended Posts

Posted (edited)

I always see questions around the Forum about how to create a ProgressBar that shows at least something is happening, despite having no way of counting (see Traditional Example.) This is where _ProgressSetMarquee() is brilliant, because it creates the Marquee style (see Image) without all the fuss of knowing about _SendMessage() etc.. Try the Example below.

Example:

Posted Image

See post #7 for a short but simple example.

or continue for those interested in API calling ...

WARNING: The code below is old, outdated and poorly scripted, therefore caution should be used when viewing this code!

  Reveal hidden contents

Traditional Example:

 

Function:

 

Example use of Function:

 

Example use of Function with inc. theming:

 

 

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

Thanks! I forgot to mention that the Style (not ExStyle) of the ProgressBar should be set with 0x0008, but its not a big deal because the Function checks the Style of the ProgressBar and changes accordingly.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted
Update: Added _ProgressSetTheme() and improved _ProgressSetMarquee(). Also added a 2nd Example showing the use of 'theming' the ProgressBar to add a custom color. See OP for more details.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted
Updated: Slight syntax change with _ProgressSetTheme(), now _ProgressSetMarquee() knows if there is a Theme set to the ProgressBar. See OP for more details.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

OK, so after all that messing around with API calls, deleting the ProgressBar to Reset the Marquee effect plus more ... all it actually took was just setting the GUICtrlSetStyle() again! :)

I was inspired by >this post to re-evaluate the code and found this little trick with GUICtrlSetStyle()!

I suppose I shouldn't be disappointed at least I learnt from this experience :)

Simple Marquee Progress:

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

Example()

Func Example()
    Local $hGUI = GUICreate('Marquee ProgressBar', 300, 90)
    Local $iProgressBar = GUICtrlCreateProgress(10, 10, 280, 20, $PBS_MARQUEE) ; Create a progressbar using the marquee style
    Local $iStart = GUICtrlCreateButton('Start', 30, 60, 85, 25)
    Local $iStop = GUICtrlCreateButton('Stop', 120, 60, 85, 25)
    Local $iReset = GUICtrlCreateButton('Stop && Reset', 210, 60, 85, 25)
    GUISetState(@SW_SHOW, $hGUI)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

            Case $iStart
                _ProgressMarquee_Start($iProgressBar) ; Start the marquee effect

            Case $iStop
                _ProgressMarquee_Stop($iProgressBar) ; Stop the marquee effect

            Case $iReset
                _ProgressMarquee_Stop($iProgressBar, True) ; Stop the marquee effect and reset the progressbar

        EndSwitch
    WEnd

    ; Tidy resources
    GUIDelete($hGUI)
EndFunc   ;==>Example

; #FUNCTION# ====================================================================================================================
; Name ..........: _ProgressMarquee_Start
; Description ...: Start the marquee effect
; Syntax ........: _ProgressMarquee_Start($iControlID)
; Parameters ....: $iControlID          - ControlID of a progressbar using the $PBS_MARQUEE style
; Return values .: Success - True
;                  Failure - False
; Author ........: guinness
; Example .......: Yes
; ===============================================================================================================================
Func _ProgressMarquee_Start($iControlID)
    Return GUICtrlSendMsg($iControlID, $PBM_SETMARQUEE, True, 50)
EndFunc   ;==>_ProgressMarquee_Start

; #FUNCTION# ====================================================================================================================
; Name ..........: _ProgressMarquee_Stop
; Description ...: Stop the marquee effect
; Syntax ........: _ProgressMarquee_Stop($iControlID[, $bReset = False])
; Parameters ....: $iControlID          - ControlID of a progressbar using the $PBS_MARQUEE style
;                  $bReset              - [optional] Reset the progressbar, True - Reset or False - Don't reset. Default is False
; Return values .: Success - True
;                  Failure - False
; Author ........: guinness
; Example .......: Yes
; ===============================================================================================================================
Func _ProgressMarquee_Stop($iControlID, $bReset = False)
    Local $bReturn = GUICtrlSendMsg($iControlID, $PBM_SETMARQUEE, False, 50)
    If $bReturn And $bReset Then
        GUICtrlSetStyle($iControlID, $PBS_MARQUEE)
    EndIf

    Return $bReturn
EndFunc   ;==>_ProgressMarquee_Stop
Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 3 months later...
Posted

How can I use this simple script:

_Main()  Func _Main()     GUICreate("Standard use of a ProgressBar()", 240, 50, -1, -1)     Local $Progress = GUICtrlCreateProgress(10, 10, 220, 20)     GUISetState(@SW_SHOW)      For $A = 1 To 100         GUICtrlSetData($Progress, $A)         Sleep(50)         If GUIGetMsg() = -3 Then ExitLoop     Next      While 1         Switch GUIGetMsg()             Case -3                 Exit         EndSwitch     WEnd EndFunc   ;==>_Main

in a way that closes it self when the bar reach 100% ?

also is there a way to set it to advance let's say based on how many applications were installed or how many files were copied etc?

Posted

Maybe you want a standard incremented ProgressBar. Have a look at GUICtrlCreateProgress() in the Help File to get an idea.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 1 month later...
Posted

Hi all.

I'm trying to use this UDF, but when running my function, the progress bar freezes. See example:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>

_Main()

Func _Main()
    Local $iProgress_1, $iButton_1, $iButton_2, $iButton_3
    GUICreate("Simple use of a Marquee ProgressBar()", 240, 90, -1, -1)
    $iProgress_1 = GUICtrlCreateProgress(10, 10, 220, 20, $PBS_MARQUEE)
    $iButton_1 = GUICtrlCreateButton("&Start", 10, 60, 70, 25)
    $iButton_2 = GUICtrlCreateButton("S&top", 85, 60, 70, 25)
    $iButton_3 = GUICtrlCreateButton("Stop && &Reset", 160, 60, 70, 25)
    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit

            Case $iButton_1
                _ProgressMarquee_Start($iProgress_1)
                _CheckPingAddress('ddd.dd')
                ;^^^^^^^^^^^^^^^^^^^^^^^^^

            Case $iButton_2
                _ProgressMarquee_Stop($iProgress_1)

            Case $iButton_3
                _ProgressMarquee_Stop($iProgress_1, 1)

        EndSwitch
    WEnd
EndFunc   ;==>_Main

; -------------------------------
Func _CheckPingAddress($sAddress)
    Local $sResult
    ConsoleWrite('>ping ' & $sAddress & '...' & @CRLF)
    $sResult = Ping( $sAddress)
    If $sResult Then
        ConsoleWrite('result: ' & $sResult & 'ms' & @CRLF)
        Return True
    Else
        ConsoleWrite('result: failure' & @CRLF)
        Return False
    EndIf
EndFunc   ;==>__CheckPingDNSAddress
;--------------------------------


Func _ProgressMarquee_Start($iControlID = -1)
    Local Const $PBM_SETMARQUEE = 1034
    Return GUICtrlSendMsg($iControlID, $PBM_SETMARQUEE, 1, 50)
EndFunc   ;==>_ProgressMarquee_Start

Func _ProgressMarquee_Stop($iControlID = -1, $iReset = 0)
    Local Const $PBS_MARQUEE = 0x0008, $PBM_SETMARQUEE = 1034
    GUICtrlSendMsg($iControlID, $PBM_SETMARQUEE, 0, 50)
    If $iReset = 1 Then
        Return GUICtrlSetStyle($iControlID, $PBS_MARQUEE)
    EndIf
    Return 1
EndFunc   ;==>_ProgressMarquee_Stop

Any suggestions how to display progress bar during the execution of my functions are welcome

Posted

I tested on Windows 7 x64 & AutoIt (Latest beta) without any problem.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

I use Windows 7 x64. AutoIt (x86)

Just installed AutoIt v3.3.7.14 (beta)

Doesn't work ...

Progress bar is showing only after function _CheckPingAddress('ddd.dd') has finished...

Posted

Weird, because when I select 'Start' the Marquee Progress starts and then your Function executes afterwards. I even added Sleep(6000) at the start of your Function and the Marquee still started.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

What about this >>

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>

_Main()

Func _Main()
    Local $iProgress_1, $iButton_1, $iButton_2, $iButton_3
    GUICreate("Simple use of a Marquee ProgressBar()", 240, 90, -1, -1)
    $iProgress_1 = GUICtrlCreateProgress(10, 10, 220, 20, $PBS_MARQUEE)
    $iButton_1 = GUICtrlCreateButton("&Start", 10, 60, 70, 25)
    $iButton_2 = GUICtrlCreateButton("S&top", 85, 60, 70, 25)
    $iButton_3 = GUICtrlCreateButton("Stop && &Reset", 160, 60, 70, 25)
    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit

            Case $iButton_1
                _ProgressMarquee_Start($iProgress_1)
                _Example()

            Case $iButton_2
                _ProgressMarquee_Stop($iProgress_1)

            Case $iButton_3
                _ProgressMarquee_Stop($iProgress_1, 1)

        EndSwitch
    WEnd
EndFunc   ;==>_Main

Func _Example()
    Sleep(4000)
    MsgBox(64, "Example", "Example")
EndFunc

Func _ProgressMarquee_Start($iControlID = -1)
    Local Const $PBM_SETMARQUEE = 1034
    Return GUICtrlSendMsg($iControlID, $PBM_SETMARQUEE, 1, 50)
EndFunc   ;==>_ProgressMarquee_Start

Func _ProgressMarquee_Stop($iControlID = -1, $iReset = 0)
    Local Const $PBS_MARQUEE = 0x0008, $PBM_SETMARQUEE = 1034
    GUICtrlSendMsg($iControlID, $PBM_SETMARQUEE, 0, 50)
    If $iReset = 1 Then
        Return GUICtrlSetStyle($iControlID, $PBS_MARQUEE)
    EndIf
    Return 1
EndFunc   ;==>_ProgressMarquee_Stop

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

Change the timeout in Ping as now it's 4 seconds, perhaps 400ms would be better.

Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

I've changed timeout to 400, now progress bar starting erlier, but also only after ping()...

In my script i have many times using ping(), and the progress bar always freezes when they run. :mellow:

Posted

I'm seeing the same issue, but the problem isn't with the Progressbar, it's with the way Ping is working. I believe that the problem is caused because Ping is using too much of the CPU or other resources which is basically freezing the script and/or the progress bar updates. I've run into this problem when using FileCopy as well, where the computer can't do both, updating my progress bar and copying a large file or folder, at the same time.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

  Reveal hidden contents

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Posted

Weird how I'm not seeing the problem though. Thanks for verifying BrewManNH.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

  • 1 year later...
Posted

Note: This UDF is deprecated as of 09/10/2012. Any questions regarding support for this UDF will not be given and users should look to using this instead of the UDF.

Thanks to all who helped me with the UDF.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
  • Recently Browsing   0 members

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