Jump to content

Another simple coloured ProgressBar


boble911
 Share

Recommended Posts

There is the cool GDIplus Progressbar but for me it has some strange effects with colour stripes instead of solid colour bar.

So, I've write this simple functions emulate the progress bar with custom background and foreground colours. It is not the UDF. It was written for personal use in quick written small program, so do not judge strictly ;) . Maybe some one find it usefull.

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


$fMain = GUICreate("Progress", 200, 100)
_ProgressCreate(8,8,184,25)
_ProgressSetBkColour(0xc0dec0)
_ProgressSetFrColour(0x20a0c0)

$bRun = GUICtrlCreateButton("GO", 8, 40)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg(1)
Select
Case $nMsg[0] = $GUI_EVENT_CLOSE And $nMsg[1] = $fMain
Exit
Case $nMsg[0] = $bRun
_ProgressSetMode(0)
_ProgressSetMaxVal(1000)
_ProgressSetVal(0)
For $i = 0 To 1000
Sleep(10)
_ProgressSetVal($i)
Next
_ProgressSetMode(1)
_ProgressSetMaxVal(1000)
_ProgressSetVal(0)
For $i = 0 To 1000
Sleep(10)
_ProgressSetVal($i)
Next

EndSelect
WEnd

Func _ProgressCreate($l, $t, $w, $h)
Global $Left = $l
Global $Top = $t
Global $Width = $w
Global $Height = $h
Global $Bk = GUICtrlCreateLabel("", $Left, $Top, $Width, $Height)
Global $Fr = GUICtrlCreateLabel("", $Left + 1, $Top + 1, 1, $Height - 2)
EndFunc

Func _ProgressInit($max, $bkColor, $frColor, $m = 0)
Global $Mode = $m
Global $MaxVal = $max
Global $Coeff = ($Width - 2) / $MaxVal
Global $BkColour = $bkColor
Global $FrColour = $frColor
GUICtrlSetBkColor($Bk, $BkColour)
GUICtrlSetBkColor($Fr, $FrColour)
GUICtrlSetState($Fr, $GUI_FOCUS)
EndFunc

Func _ProgressSetMaxVal($val)
Global $MaxVal = $val
Global $Coeff = ($Width - 2) / $MaxVal
EndFunc

Func _ProgressSetBkColour($colour)
Global $BkColour = $colour
GUICtrlSetBkColor($Bk, $BkColour)
EndFunc

Func _ProgressSetFrColour($colour)
Global $FrColour = $colour
GUICtrlSetBkColor($Fr, $FrColour)
EndFunc

Func _ProgressSetMode($val)
Global $Mode = $val
EndFunc

Func _ProgressSetMax()
_ProgressSetVal($MaxVal)
EndFunc

Func _ProgressSetVal($val)
Local $l ;= ($Left + 1) + ($Width / 2)
Local $w ;= 1

If $Mode = 0 Then
$l = $Left + 1
Select
Case $val >= $MaxVal
$w = $Width - 2
Case ($val * $Coeff) <= 1
$w = 1
Case Else
$w = Int($val * $Coeff)
EndSelect
ElseIf $Mode = 1 Then
Select
Case $val >= $MaxVal
$l = $Left + 1
$w = $Width - 2
Case ($val * $Coeff) <= 1
$l = Int(($Left + 1) + ($Width / 2))
$w = 1
Case Else
$w = Int($val * $Coeff)
$l = Int(($Left + 1) + ($Width -2 - $w) / 2)
EndSelect
EndIf
GUICtrlSetPos($Fr, $l, $Top + 1, $w, $Height - 2)
GUICtrlSetState($Fr, $GUI_FOCUS)
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...