Jump to content

Setting Color For Progress Bar


 Share

Recommended Posts

Hello, I'm trying to change the color of my progress bar and the manual for GUICtrlSetColor says: Progress controls cannot be painted if the "Windows XP style" is used. I cannot find where to specify the windows xp style (or not to). However, I cannot change the color. Any ideas?

#include <GUIConstants.au3>
#notrayicon
$checkRun = "Emc Tool"
If WinExists($checkRun) Then Exit
$main_gui= GUICreate("Emc Tool", 350, 280)
GUISetBkColor (0x0f0f0f)
Global $defaultstatus = "Ready"
Global $status
$statuslabel = GUICtrlCreateLabel ($defaultstatus,0,240,350,18,BitOr($SS_SIMPLE,$SS_SUNKEN))
GUICtrlSetColor ( $statuslabel, 0x76EE00)
$button = GUICtrlCreateLabel ("Ping", 150, 60, 60, 20)
GUICtrlSetColor ( $button, 0x76EE00)
$LabelTime = GUICtrlCreateLabel(" ", 230, 218, 115,17,BitOr($SS_SIMPLE,$SS_SUNKEN))
GUICtrlSetColor ($LabelTime, 0x76EE00)

$name = GUICtrlCreateLabel(" Hello " & @username, 10, 218, 98,17,BitOr($SS_SIMPLE,$SS_SUNKEN))
GUICtrlSetFont ($name, 11)
GUICtrlSetColor ($name, 0x76EE00)
; Show the GUI
GUISetState ()

While 1
 $msg = GUIGetMsg()

 GUICtrlSetData($LabelTime, @MON & "." & @MDAY & "." & @YEAR & "   " & @HOUR & "." & @MIN & "." & @SEC)
 Select
  Case $msg = $GUI_EVENT_CLOSE
      DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $main_gui, "int", 1000, "long", 0x00090000);fade-out
      ExitLoop
  Case $msg = $button
      uptime()
 EndSelect
WEnd


;;;;;;;;;;;;;;;;;
func uptime()
  $vServerClip=clipget()
  $vServerString=stringsplit($vServerClip,@TAB)
  If $vServerString[0] >= 22 Then 
   $vServer = $vServerString[22]
   $statuslabel = GUICtrlCreateLabel ("running uptime                                                                                                                                             ",0,240,350,18,BitOr($SS_SIMPLE,$SS_SUNKEN))
   GUICtrlSetColor ( $statuslabel, 0x76EE00)
   $progressbar1 = GUICtrlCreateProgress (226,240,125,18,$PBS_SMOOTH);,$ss_SUNKEN)
   GUICtrlSetColor ( $progressbar1, 0x76EE00)
   $wait = 2
   $s = 0
   GUICtrlSetColor(-1,32250)
   For $i = $s To 100
    GUICtrlSetData ($progressbar1,$i)
    Sleep($wait)
   next
   dim $aMy[6]
   $mycmd=" /c %systemroot%\system32\ping -n 1  tserver& pause"
   $mycmd0=stringreplace($mycmd,"tserver",$vServer)
   $aMy[1]= @ComSpec
   $aMy[2]= $mycmd0
   Run($aMy[1] & $aMy[2])
  else 
   msgbox(48,"Error", "Please copy the node into the clipboard.")
  endif
 $statuslabel = GUICtrlCreateLabel ("Ready                                                                                                                                                                     ",0,240,350,18,BitOr($SS_SIMPLE,$SS_SUNKEN))
 GUICtrlSetColor ( $statuslabel, 0x76EE00)
 $progressbar1 = GUICtrlCreateProgress (226,240,125,18,$PBS_SMOOTH);,$ss_SUNKEN)
   GUICtrlSetColor ( $progressbar1, 0x76EE00)
endfunc
Link to comment
Share on other sites

sorry, for a working version of the above code try below. Just copy a server name or ip address into the clipboard:

#include <GUIConstants.au3>
#notrayicon
$checkRun = "Emc Tool"
If WinExists($checkRun) Then Exit
$main_gui= GUICreate("Emc Tool", 350, 280)
GUISetBkColor (0x0f0f0f)
Global $defaultstatus = "Ready"
Global $status
$statuslabel = GUICtrlCreateLabel ($defaultstatus,0,240,350,18,BitOr($SS_SIMPLE,$SS_SUNKEN))
GUICtrlSetColor ( $statuslabel, 0x76EE00)
$button = GUICtrlCreateLabel ("Ping", 150, 60, 60, 20)
GUICtrlSetColor ( $button, 0x76EE00)
$LabelTime = GUICtrlCreateLabel(" ", 230, 218, 115,17,BitOr($SS_SIMPLE,$SS_SUNKEN))
GUICtrlSetColor ($LabelTime, 0x76EE00)

$name = GUICtrlCreateLabel(" Hello " & @username, 10, 218, 98,17,BitOr($SS_SIMPLE,$SS_SUNKEN))
GUICtrlSetFont ($name, 11)
GUICtrlSetColor ($name, 0x76EE00)
; Show the GUI
GUISetState ()

While 1
 $msg = GUIGetMsg()

 GUICtrlSetData($LabelTime, @MON & "." & @MDAY & "." & @YEAR & "   " & @HOUR & "." & @MIN & "." & @SEC)
 Select
  Case $msg = $GUI_EVENT_CLOSE
      DllCall("user32.dll", "int", "AnimateWindow", "hwnd", $main_gui, "int", 1000, "long", 0x00090000);fade-out
      ExitLoop
  Case $msg = $button
      uptime()
 EndSelect
WEnd


;;;;;;;;;;;;;;;;;
func uptime()
   $vServerClip=clipget()
   $vServerString=stringsplit($vServerClip,@TAB)
   $statuslabel = GUICtrlCreateLabel ("running uptime                                                                                                                                             ",0,240,350,18,BitOr($SS_SIMPLE,$SS_SUNKEN))
   GUICtrlSetColor ( $statuslabel, 0x76EE00)
   $progressbar1 = GUICtrlCreateProgress (226,240,125,18,$PBS_SMOOTH);,$ss_SUNKEN)
   GUICtrlSetColor ( $progressbar1, 0x76EE00)
   $wait = 2
   $s = 0
   GUICtrlSetColor(-1,32250)
   For $i = $s To 100
    GUICtrlSetData ($progressbar1,$i)
    Sleep($wait)
   next
   dim $aMy[6]
   $mycmd=" /c %systemroot%\system32\ping -n 1  tserver& pause"
   $mycmd0=stringreplace($mycmd,"tserver",clipget())
   $aMy[1]= @ComSpec
   $aMy[2]= $mycmd0
   Run($aMy[1] & $aMy[2])
   $statuslabel = GUICtrlCreateLabel ("Ready                                                                                                                                                                       ",0,240,350,18,BitOr($SS_SIMPLE,$SS_SUNKEN))
   GUICtrlSetColor ( $statuslabel, 0x76EE00)
   $progressbar1 = GUICtrlCreateProgress (226,240,125,18,$PBS_SMOOTH);,$ss_SUNKEN)
   GUICtrlSetColor ( $progressbar1, 0x76EE00)
endfunc

Please note, the following code works to change to color. However, I'm not sure why it works and the above doesn't.

#include <GUIConstants.au3>

GUICreate("My GUI Progressbar",220,100, 100,200)
$progressbar1 = GUICtrlCreateProgress (10,10,200,20)
GUICtrlSetColor($progressbar1,0x76EE00)
$progressbar2 = GUICtrlCreateProgress (10,40,200,20,$PBS_SMOOTH,$ss_Sunken)
GUICtrlSetColor($progressbar2,0x76EE00)
$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
    $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
Link to comment
Share on other sites

I figured it out. I had an entry that wasn't needed (due to copying code from another function). Thanks anyway!

I removed: GUICtrlSetColor(-1,32250)

I don't get it... How did that fix the problem? :mellow:

I have a really cool progress bar I wrote (I'll post it when I get to work) that smoothly changes color based on the progress. Full red at 0%, smoothly transitions to full blue at 50%, and then smoothly goes to full green at 100%. Works great in WINE, Win2KPro, Win2KAS, and Win2003, but the progress bar stays green from start to finish in XP.

I saw the note about "Windows XP style" but have the same questions: How did that get set? Is that just a "feature" of XP? How do I change it? :)

P.S. There are other attributes, like the default font size in message boxes and GUIs that seem to be different in XP than any other Windows, too.

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

I don't get it... How did that fix the problem? :)

I have a really cool progress bar I wrote (I'll post it when I get to work) that smoothly changes color based on the progress. Full red at 0%, smoothly transitions to full blue at 50%, and then smoothly goes to full green at 100%. Works great in WINE, Win2KPro, Win2KAS, and Win2003, but the progress bar stays green from start to finish in XP.

I saw the note about "Windows XP style" but have the same questions: How did that get set? Is that just a "feature" of XP? How do I change it? :mellow:

P.S. There are other attributes, like the default font size in message boxes and GUIs that seem to be different in XP than any other Windows, too.

Here is my demo, MultiColorProgressBar.au3, which works on every Windows except XP:

#include <GuiConstants.au3>

$GuiHandle = GUICreate("Progress Bar Test", 300, 130)
$ProgBar_1 = GUICtrlCreateProgress(10, 10, 280, 30, $PBS_Smooth)
$UpButton = GUICtrlCreateButton("UP", 15, 50, 76, 40)
$DownButton = GUICtrlCreateButton("Down", 112, 50, 76, 40)
$StopButton = GUICtrlCreateButton("STOP", 209, 50, 76, 40)
$Label_1 = GUICtrlCreateLabel("Red = 0, Green = 0, Blue = 0, Color = 0xFF0000", 10, 100, 280, 20, $SS_Center)
GUISetState()

$Progress = 0; Will be 0 thru 1000
$Increment = 0
While(1)
    $GuiMsg = GUIGetMsg()
    Select
        Case $GuiMsg = $GUI_EVENT_CLOSE
            Exit
        Case $GuiMsg = $UpButton
            $Increment = +1
        Case $GuiMsg = $DownButton
            $Increment = -1
        Case $GuiMsg = $StopButton
            $Increment = 0
        EndSelect
    _SetProgColor()
WEnd

Func _SetProgColor()
    $Progress = $Progress + $Increment
    If $Progress < 0 Then $Progress = 0
    If $Progress > 1000 Then $Progress = 1000
    GUICtrlSetData($ProgBar_1, Int($Progress / 10))
    
    $Redness = Int(255 - ($Progress / 1000 * 512))
    If $Redness < 0 Then $Redness = 0
        
    $Greeness = Int(($Progress / 1000 * 512) - 257)
    If $Greeness < 0 Then $Greeness = 0
        
    $Blueness = Int(255 - ($Redness + $Greeness))
    
    $ProgColor = ($Redness * 256 * 256) + ($Greeness * 256) + $Blueness
    GUICtrlSetData($Label_1, "Red = " & $Redness & ", Green = " & $Greeness & ", Blue = " & $Blueness & ", Color = 0x" & Hex($ProgColor, 6))
    GUICtrlSetColor($ProgBar_1, $ProgColor)
EndFunc

Looking for how to make the changing color of the progress bar work for XP also... :)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Add 1 line to it and it will work in XP with themes

#include <GuiConstants.au3>

DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)

$GuiHandle = GUICreate("Progress Bar Test", 300, 130)
$ProgBar_1 = GUICtrlCreateProgress(10, 10, 280, 30, $PBS_Smooth)
$UpButton = GUICtrlCreateButton("UP", 15, 50, 76, 40)
$DownButton = GUICtrlCreateButton("Down", 112, 50, 76, 40)
$StopButton = GUICtrlCreateButton("STOP", 209, 50, 76, 40)
$Label_1 = GUICtrlCreateLabel("Red = 0, Green = 0, Blue = 0, Color = 0xFF0000", 10, 100, 280, 20, $SS_Center)
GUISetState()

$Progress = 0; Will be 0 thru 1000
$Increment = 0
While(1)
    $GuiMsg = GUIGetMsg()
    Select
        Case $GuiMsg = $GUI_EVENT_CLOSE
            Exit
        Case $GuiMsg = $UpButton
            $Increment = +1
        Case $GuiMsg = $DownButton
            $Increment = -1
        Case $GuiMsg = $StopButton
            $Increment = 0
        EndSelect
    _SetProgColor()
WEnd

Func _SetProgColor()
    $Progress = $Progress + $Increment
    If $Progress < 0 Then $Progress = 0
    If $Progress > 1000 Then $Progress = 1000
    GUICtrlSetData($ProgBar_1, Int($Progress / 10))
    
    $Redness = Int(255 - ($Progress / 1000 * 512))
    If $Redness < 0 Then $Redness = 0
        
    $Greeness = Int(($Progress / 1000 * 512) - 257)
    If $Greeness < 0 Then $Greeness = 0
        
    $Blueness = Int(255 - ($Redness + $Greeness))
    
    $ProgColor = ($Redness * 256 * 256) + ($Greeness * 256) + $Blueness
    GUICtrlSetData($Label_1, "Red = " & $Redness & ", Green = " & $Greeness & ", Blue = " & $Blueness & ", Color = 0x" & Hex($ProgColor, 6))
    GUICtrlSetColor($ProgBar_1, $ProgColor)
EndFunc

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Add 1 line to it and it will work in XP with themes

DllCall("uxtheme.dll", "none", "SetThemeAppProperties", "int", 0)
That did it! Working on all Windows versions I can test on now! :)

Thanks! :mellow:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...