Jump to content

Show percentage in the middle of the progress bar


Loc
 Share

Recommended Posts

There are some errors when making the percentage displayed in the progress bar:
- When using guictrlsetdata at the same time, the percentage is lost.
- Using sleep can display the percentage bar, but when the progress bar = 100, the progress is lost.
Please help me find a way to keep this percentage(Label) always showing on progress bar with.
Test code is below:

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


#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Progress", 367, 148, 192, 124)
$Progress = GUICtrlCreateProgress(56, 48, 254, 25)
$Percentage = GUICtrlCreateLabel("0%", 66, 48, 233, 25, $SS_CENTER + $SS_CENTERIMAGE)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

For $i = 0 To 100
    GUICtrlSetData($Progress, $i)
    GUICtrlSetData($Percentage, $i & '%')
    Sleep(10)
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Thanks!

Link to comment
Share on other sites

Try this :

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPI.au3>

Global Const $AlphaKey = 0xFFFFFF

$hGUI = GUICreate("GUI", 294, 69, 192, 124)
$idProgressBar = GUICtrlCreateProgress(8, 24, 278, 17)
$hGUI_c = GUICreate("", 50, 17, (8+278-50)/2, 24, $WS_POPUP,$WS_EX_LAYERED+$WS_EX_TRANSPARENT+$WS_EX_MDICHILD, $hGUI)
GUISetBkColor($AlphaKey, $hGUI_c)
$idLabel = GUICtrlCreateLabel("0", 0, 0, 50, 17, $SS_CENTER)
GUICtrlSetFont(-1, 10)
_WinAPI_SetLayeredWindowAttributes($hGUI_c, $AlphaKey)
GUISetState(@SW_SHOW, $hGUI)
GUISetState(@SW_SHOWNA, $hGUI_c)

For $i = 0 To 50
    GUICtrlSetData($idProgressBar, $i*2)
    GUICtrlSetData($idLabel, $i*2 & " %")
    Sleep(100)
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

 

Link to comment
Share on other sites

Link to comment
Share on other sites

for example:

Progress1

Progress2

Progress3

Progress...

All these progress has a percentage on the progress and that percentage is always visible. Because these processes are always not linked. If you have a udf or a function that passes a parameter like Guictrlcreateprogress but has a percentage in the middle of the progress bar that's great.

Link to comment
Share on other sites

a possible easy way

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
; -----
#include <WinAPITheme.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Progress", 367, 148, 192, 124)
; $Progress = GUICtrlCreateProgress(56, 48, 254, 25)
; -----
Global $ahProgress[4], $ahPercentage[4]

For $i = 0 To 3
    $ahProgress[$i] = GUICtrlCreateProgress(56, 10 + 30 * $i, 254, 25)
    _WinAPI_SetWindowTheme(GUICtrlGetHandle(-1), "", "")
    GUICtrlSetBkColor(-1, 0x00ff00)
    GUICtrlSetColor(-1, 0xff0000) ; color of the advancing bar

    $ahPercentage[$i] = GUICtrlCreateLabel("0%", 66, 10 + 30 * $i, 233, 25, $SS_CENTER + $SS_CENTERIMAGE)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
Next
; -----
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

For $i = 0 To 100
    For $ii = 0 To 3
        GUICtrlSetData($ahProgress[$ii], $i )
        GUICtrlSetData($ahPercentage[$ii], GUICtrlRead($ahProgress[0]) & '%')
    Next
    Sleep(10)
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

just for fun, slightly modified and dressed as functions
there are 2 paired functions:
_GUICtrlCreateProgressCustom()
allows you to create a customized Progressbar with the percentage superimposed. You can choose the colors of the background and of the progress bar. You can also optionally choose at what percentage of progress the color of the progress bar can change to another color.
_GUICtrlSetDataProgressCustom()
used to set the value of the custom progress bar

hope you have fun :)

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
; -----
#include <WinAPITheme.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Progress", 367, 148, 192, 124)
; -----
; create some example pregress bars
Global $ahProgress[6] ; to store bars references
$ahProgress[0] = _GUICtrlCreateProgressCustom(20, 10, 255, 25) ; plain progress bar
$ahProgress[1] = _GUICtrlCreateProgressCustom(20, 40, 255, 25, -1, 0xFFFFFF, 0x00ff00, 70, 0xff00ff) ; change color when >= 70%
$ahProgress[2] = _GUICtrlCreateProgressCustom(20, 70, 255, 25, 0x04, 0xFFFFFF, 0x00ff00, 100, 0xff0000) ; vertical filling effect + red at 100%
$ahProgress[3] = _GUICtrlCreateProgressCustom(20, 100, 255, 25, -1, 0xFFFFFF, 0x5555aa, 90, 0xaaaaff) ; change color when >= 90%
$ahProgress[4] = _GUICtrlCreateProgressCustom(290, 10, 25, 115, 0x04, 0x7f7f7f, 0x00ffff, 80, 0xaaaa00) ; vertical ; darker background ; some ugly colors
$ahProgress[5] = _GUICtrlCreateProgressCustom(330, 10, 25, 115, 0x04, 0x7f7f7f, 0xff0000, 100, 0x00ff00) ; vertical ; darker background ; some ugly colors
; -----
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

; update the progess bars
For $i = 0 To 100
    For $ii = 0 To UBound($ahProgress) - 1
        _GUICtrlSetDataProgressCustom($ahProgress[$ii], $i)
    Next
    Sleep(100)
Next

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

; #FUNCTION# ====================================================================================================================
; Name ..........: _GUICtrlCreateProgressCustom
; Description ...:
; Syntax ........: _GUICtrlCreateProgressCustom($Left, $Top, $Width, $Height[, $Style = -1[, $BackColor = 0xFFFFFF[,
;                  $ForeColor = 0x00FF00[, $Warn = 0[, $WarnColor = 0xFF0000]]]]])
; Parameters ....: $Left                - The left side of the control.
;                  $Top                 - The top of the control.
;                  $Width               - The width of the control.
;                  $Height              - The height of the control.
;                  $Style               - [optional] Defines the style of the control. Default is -1.
;                                         the style con be useful to set a vertical Progress (use $PBS_VERTICAL 0x04)
;                  $BackColor           - [optional] The background RGB color to use. Default is 0xFFFFFF.
;                  $ForeColor           - [optional] The Progress bar RGB color to use. Default is 0x00FF00.
;                  $Warn                - [optional] A value (inclusive) beyond which the bar color changes to the warning color.
;                                         Default is 0 (disabled). (ie: use 101 to signal if a value > 100 has been set)
;                  $WarnColor           - [optional] The Progress bar RGB color to use while in warn values. Default is 0xFF0000.
; Return values .:                      Returns an 1D 5 elements array as follow:
;                                       [0] the identifier (controlID) of the new control.
;                                       [1] the identifier (controlID) of the overlapped label control.
;                                       [2] the Progress bar RGB color assigned to this bar.
;                                       [3] the "warn" value at which and beyond which the bar color changes to the warning color.
;                                       [4] The Progress bar RGB color to use while in warn values.
; Author ........: Chimp
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GUICtrlCreateProgressCustom($Left, $Top, $Width, $Height, $Style = -1, $BackColor = 0xFFFFFF, $ForeColor = 0x00FF00, $Warn = 0, $WarnColor = 0xFF0000)
    Local $aProgrStruct[5], $LabelWidth = 30, $LabelHeight = 25
    $aProgrStruct[0] = GUICtrlCreateProgress($Left, $Top, $Width, $Height, $Style)
    _WinAPI_SetWindowTheme(GUICtrlGetHandle(-1), "", "")
    GUICtrlSetBkColor(-1, $BackColor)
    GUICtrlSetColor(-1, $ForeColor) ; color of the advancing bar
    $aProgrStruct[1] = GUICtrlCreateLabel("0%", _
            $Left + ($Width / 2) - ($LabelWidth / 2), _
            $Top + ($Height / 2) - ($LabelHeight / 2), _
            $LabelWidth, $LabelHeight, $SS_CENTER + $SS_CENTERIMAGE)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    ; optional
    $aProgrStruct[2] = $ForeColor
    $aProgrStruct[3] = $Warn
    $aProgrStruct[4] = $WarnColor
    Return $aProgrStruct
EndFunc   ;==>_GUICtrlCreateProgressCustom

; #FUNCTION# ====================================================================================================================
; Name ..........: _GUICtrlSetDataProgressCustom
; Description ...:
; Syntax ........: _GUICtrlSetDataProgressCustom($aProgress, $iValue)
; Parameters ....: $aProgress           - the array returned by the _GUICtrlCreateProgressCustom() function.
;                  $iValue              - an integer value to set the progress bar to.
; Return values .: None
; Author ........: Chimp
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _GUICtrlSetDataProgressCustom($aProgress, $iValue)
    Local $iFC = $aProgress[2]
    If $aProgress[3] And $iValue >= $aProgress[3] Then $iFC = $aProgress[4]
    GUICtrlSetColor($aProgress[0], $iFC)
    GUICtrlSetData($aProgress[0], $iValue)
;~ GUICtrlSetData($aProgress[1], $iValue & '%')
    GUICtrlSetData($aProgress[1], GUICtrlRead($aProgress[0]) & '%')
EndFunc   ;==>_GUICtrlSetDataProgressCustom

 

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

  • 7 months later...

Sorry for repeating the topic even though it has been resolved.
Can anyone help me to calculate these 2 progress bars?
Example: Progress1 - runs from 0% to 100% then Progress 2 = 1% .
I download the file using InetGet
$download = InetGet($url)
Round(InetGetInfo($hDownload,0)
help me

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