Jump to content

help me put an end to this flickering on a rapid label update once and for all :(


 Share

Recommended Posts

I call it the flicker of death.

#include <GUIConstants.au3>
Global $var = 0
GUICreate ("flicker of death", 200, 40)
$label = GUICtrlCreateLabel ("", 0, 0, 200, 40)
GUICtrlSetBkColor(-1, 0x000000)
GUICtrlSetColor(-1, 0xFFFFFF)
GUISetState ()
While 1
    $msg = GUIGetMsg ()
    If $msg = $GUI_EVENT_CLOSE Then
        ExitLoop
    EndIf
    $var += 1
    GUICtrlSetData($label, $var)
WEnd
Link to comment
Share on other sites

add sleep(100) in the while loop.

or whatever amount you want to sleep really.

it will cut down on cpu usage and flash less.

Well, I gotta say, this DOES work. Although it is no longer "rapid updating".

Anyway, from all the posts I read about this when searching, this seems to be the only solution.

Thanks for your time!

Link to comment
Share on other sites

Use ControlSetText instead of GUICtrlSetData.

Update only if new text is different from old text (in your example it always is, so this point is irrelevant, but in other uses it may not). That's just common sense.

Also, if you want to do it from the main loop, use event mode. Otherwise, adlib or timer. If you do in GuiGetMsg loop, the frequency it triggers depends on messages generated for the window. In idle mode it's ~10ms, much more if you move mouse over GUI. Unless the purpose of your counter is to count GUI events, such disparity isn't useful at all.

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

  • 3 weeks later...
  • 3 years later...

I know this is somewhat of a necro, but I'm adding this in case others Google this and find this topic like I did.

I ran into a similar problem using a script that was reading lines in an excel file. Here is how I resolved the issue:

$time = TimerInit()
 For $row = "1" To $totalRows
  $num = $num + _ExcelReadCell($book, $row, 8)
  $diff = TimerDiff($time)
  If $diff > 100 Then
   GUICtrlSetData($lbl2, "Reading line " & $row & " of " & $totalRows & ", " & $num & " Projects")
   $time = TimerInit()
  EndIf
 Next

With the wait set to 50ms, the update speed didn't look any different visually to me, so if you want it to look completely smooth you can set it to that.

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