Jump to content

Progressbar Change Colors


jfcby
 Share

Recommended Posts

Hi,

Is it possibe to change the colors of a progrgressbar? The help said it is possible but in the following code GUICtrlSetColor and GUICtrlSetBkColor does not work. I searched this forum but did not find any examples using them either.

Script Code:

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.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, -1, $WS_EX_WINDOWEDGE)
    GUICtrlSetColor(-1, 0x000000) ; Black
    GUICtrlSetBkColor(-1, 0xC2C2C2)     ; Gray  
    $progressbar2 = GUICtrlCreateProgress(10, 40, 200, 20, $PBS_SMOOTH)
    GUICtrlSetColor(-1, 0x000000) ; Black
    GUICtrlSetBkColor(-1, 0xC2C2C2)     ; Gray  
    $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

Thank you for your help,

jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

Try this...

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.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, -1, $WS_EX_WINDOWEDGE)
    GUICtrlSetColor(-1, 0x000000) ; Black
    GUICtrlSetBkColor(-1, 0xC2C2C2)     ; Gray
    $progressbar2 = GUICtrlCreateProgress(10, 40, 200, 20, $PBS_SMOOTH)
    GUICtrlSetColor(-1, 0x000000) ; Black
    GUICtrlSetBkColor(-1, 0xC2C2C2)     ; Gray
    $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)
                    GUICtrlSetColor($progressbar2, 0xFF0000)
                EndIf

                $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

If you learn from It, it's not a mistake

Link to comment
Share on other sites

it is possible, but only in it's plain style, any other theme/style will disable it's ability to change colors,

in order to set the progress as plain style, try this:

DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle($progressbar1), "wstr", 0, "wstr", 0)
GUICtrlSetStyle($progressbar1, BitOr($GUI_SS_DEFAULT_PROGRESS, $PBS_SMOOTH));doesn't have to be smooth, but I personally like this better

and here's the full code:

#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.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, -1, $WS_EX_WINDOWEDGE)
    
    DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle(-1), "wstr", 0, "wstr", 0)
    GUICtrlSetStyle($progressbar1, BitOr($GUI_SS_DEFAULT_PROGRESS, $PBS_SMOOTH))
    
    GUICtrlSetColor(-1, 0x000000) ; Black
    GUICtrlSetBkColor(-1, 0xC2C2C2)     ; Gray  
    $progressbar2 = GUICtrlCreateProgress(10, 40, 200, 20, $PBS_SMOOTH)
    
    DllCall("UxTheme.dll", "int", "SetWindowTheme", "hwnd", GUICtrlGetHandle(-1), "wstr", 0, "wstr", 0)
    GUICtrlSetStyle($progressbar2, BitOr($GUI_SS_DEFAULT_PROGRESS, $PBS_SMOOTH))
    
    GUICtrlSetColor(-1, 0x000000) ; Black
    GUICtrlSetBkColor(-1, 0xC2C2C2)     ; Gray  
    $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
Edited by sandin
Link to comment
Share on other sites

Link to comment
Share on other sites

The help said it is possible but in the following code GUICtrlSetColor and GUICtrlSetBkColor does not work. I searched this forum but did not find any examples using them either.

The helpfile also said:

Checkbox, Radio or Progress controls cannot be painted if the "Windows XP style" is used.

The "Remarks"-section should be read, not skipped over >_<
Link to comment
Share on other sites

@Scriptonize

Are you trying to run your script? This does not work.

I did, it worked fine.

I will recheck, maybe something went wrong copying the code...

[[EDIT]]

It does work like a charm.

Running XP-SP3 (Classic style) and AutoIt v3.3.0.0

Edited by Scriptonize

If you learn from It, it's not a mistake

Link to comment
Share on other sites

Link to comment
Share on other sites

It does work like a charm.

Running XP-SP3 (Classic style) and AutoIt v3.3.0.0

How do you change Win XP to (Classic Style)?

Thank you for your help,

jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

Link to comment
Share on other sites

Another way.

#Include <WinAPIEx.au3>

Global $hForm, $Theme = _WinAPI_GetThemeAppProperties()

$hForm = GUICreate('MyGUI', 310, 189)
GUISetFont(8.5, 400, 0, 'MS Shell Dlg', $hForm)
GUICtrlCreateGroup('Group', 10, 10, 140, 95)
_WinAPI_SetThemeAppProperties($STAP_ALLOW_NONCLIENT)
GUICtrlCreateCheckbox('Check1', 22, 26, 120, 23)
GUICtrlCreateCheckbox('Check2', 22, 49, 120, 23)
GUICtrlCreateCheckbox('Check3', 22, 72, 120, 23)
_WinAPI_SetThemeAppProperties($Theme)
GUICtrlCreateGroup('Group', 160, 10, 140, 95)
GUICtrlCreateRadio('Radio1', 172, 26, 120, 23)
GUICtrlCreateRadio('Radio2', 172, 49, 120, 23)
GUICtrlCreateRadio('Radio3', 172, 72, 120, 23)
_WinAPI_SetThemeAppProperties($STAP_ALLOW_NONCLIENT)
GUICtrlCreateProgress(10, 121, 290, 20)
GUICtrlSetColor(-1, 0xFF0000)
GUICtrlSetData(-1, 20)
_WinAPI_SetThemeAppProperties($Theme)
GUICtrlCreateButton('OK', 120, 154, 70, 23)
GUISetState()

Do
Until GUIGetMsg() = -3

WinAPIEx.au3

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