Jump to content

a problem with guictrlsetbkcolor


Recommended Posts

Opt("GUIOnEventMode" ,1)
#include <StaticConstants.au3>
#include <GUIConstants.au3>
$level=0
$max=100
$gui=GUICreate("",600,600)
GUISetOnEvent($GUI_EVENT_CLOSE , "quit")
Dim $ctrl[1000]
For $i=1 To $max
    $ctrl[$i]=GUICtrlCreateLabel("" , 10,3*$i-$i,100,3,$SS_SUNKEN)
Next
GUISetState()
Func setlevel($clevel)
    If $clevel<$level Then
        For $i=$level To $clevel Step -1
            GUICtrlSetBkColor($ctrl[$max-$i] , "0x"&Hex(Random(1,256,1),2)&Hex(Random(1,256,1),2)&Hex(Random(1,255,1),2));0xECE9D8)
            _sleep(0)
        Next
    Else
        For $i=$level To $clevel-1
            GUICtrlSetBkColor($ctrl[$max-$i],"0x"&Hex(Random(1,256,1),2)&Hex(Random(1,256,1),2)&Hex(Random(1,255,1),2))
            _sleep(0)
        Next
    EndIf
    $level=$clevel
EndFunc
$lev=GUICtrlCreateLabel("" , 200 , 10 , 40 , 40)
$p=0
$add=1
For $i=1 To 10
    $p+=$add
    setlevel($p)
    If $p=$max Or $p=0 Then $add*=-1
    GUICtrlSetData($lev , $p&"%")
    _sleep(10)
Next
For $i=1 To 390
    $x=Random(1,$max,1)
    GUICtrlSetData($lev , $x&@CRLF&$i)
    setlevel($x)
    _sleep(1)
Next
While 1
    Sleep(100)
WEnd
Func quit()
    Exit
EndFunc
Func _sleep($ms)
    $timer=TimerInit()
    While TimerDiff($timer)<$ms
    WEnd
    Return TimerDiff($timer)
EndFunc

So .. this script makes something like a progress bar from labels and then with setlevel($level) sets the progress to random values

the problem is ... when the number is high...

For $i=1 To 390

the background color changes to the default color :|

if it dosen't do that for you just increase the number... it dosen't always start at the same step

any ideea what is causing this??

Only two things are infinite, the universe and human stupidity, and i'm not sure about the former -Alber EinsteinPractice makes perfect! but nobody's perfect so why practice at all?http://forum.ambrozie.ro

Link to comment
Share on other sites

Gosh, this is odd behaviour! :P

It seems to be due to using Hex() on Random(1,x,1) numbers where x > 110 but only when GUICtrlSetBkColor has been used more than 10,000 times.?!?!??!?!?

I think the devs need to see this.

Example reproducing error:

GUICreate("", 229, 187, 193, 115)
$Label = GUICtrlCreateLabel("", 10, 10, 100, 5)
GUISetState()

$ColorChangeLimit = 10000   ;erratic behaviour with Hex(Random()) at/after this iteration limit!!!!!!
$HexLimit = 110             ;erratic behaviour with Hex(Random()) at/after this hex limit!!!!!!

For $i = 1 to $ColorChangeLimit
    GUICtrlSetBkColor($Label,"0x" & Hex(Random(1,$HexLimit,1),2) & Hex(Random(1,$HexLimit,1),2) & Hex(Random(1,$HexLimit,1),2))
Next

Do
Until GUIGetMsg() = -3

The above script fails to set the label color correctly when $i approaches the loop limit approx half the time.

Try changing $ColorChangeLimit to 9000......problem goes away.

or

Try changin $HexLimit to 100....problem goes away.

Very odd. :P

Anyone any ideas?

Edited by andybiochem
- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
Link to comment
Share on other sites

So .. this script makes something like a progress bar from labels and then with setlevel($level) sets the progress to random values

the problem is ... when the number is high... the background color changes to the default color :|

if it dosen't do that for you just increase the number... it dosen't always start at the same step

any ideea what is causing this??

As a sort-of fix to your problem, try capping the number of times you GUICtrlSetBkColor to less than 10,000.

- Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
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...