Jump to content
Sign in to follow this  
lemony

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

Recommended Posts

lemony

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

Share this post


Link to post
Share on other sites
Tomb

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.

Share this post


Link to post
Share on other sites
lemony

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!

Share this post


Link to post
Share on other sites
Siao

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"

Share this post


Link to post
Share on other sites
lemony

ControlSetText makes it flicker-free :)

Nice one!

And yeah, I will be switching it to on event mode. Thanks for the advice and for solving this one for me!

Share this post


Link to post
Share on other sites
dmob

Nice one, guys.

How do I stop the flicker when loading a ListView. I tried adding the sleep, but it still flickers.

Share this post


Link to post
Share on other sites
rasim

dalisuit

How do I stop the flicker when loading a ListView. I tried adding the sleep, but it still flickers.

_GUICtrlListView_BeginUpdate()

_GUICtrlListView_EndUpdate()

Share this post


Link to post
Share on other sites
dmob

Thanks Rasim for pointing me in the right direction, I will try that.

Share this post


Link to post
Share on other sites
koresho

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.

Share this post


Link to post
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
Sign in to follow this  

×