Page 1 of 1

Vista / Win7 progress bar realtime updating fix

Posted: Fri Dec 18, 2009 11:09 pm
by luis
Sorry if something similar was already posted, I didn't find it.

Well, probably you noticed the fact win 7 / vista are using a buffering technique (kind of interpolation) to smooth the progress bar update especially when there are some big jumps in the update of the position value.

All nice and well, but when you go smootly from 1 to 100 for example, half of the time the bar is still at 50%-75% when you are closing your pretty window. Not nice.

This is a simple fix (sort of). Tested on win 7, should work on vista too I believe.

Code: Select all

EnableExplicit

#VISTA_PROGBAR_RESOLUTION = 100 ; this should be enough, higher multipliers = higher resolution

Macro VISTA_PROGBAR_FIX (topvalue)
topvalue * #VISTA_PROGBAR_RESOLUTION
EndMacro

Procedure SetVistaProgressBarValue  (nGadget, iValue)
; hack to partially fix the silly vista/win 7 behaviour
SetGadgetState(nGadget, iValue * #VISTA_PROGBAR_RESOLUTION)
SetGadgetState(nGadget, iValue * #VISTA_PROGBAR_RESOLUTION - 1)
SetGadgetState(nGadget, iValue * #VISTA_PROGBAR_RESOLUTION )
EndProcedure



; TEST PROGRAM

#DEFINE_FIX_ENABLED = 1 ; TRY THIS

Enumeration 
#WIN_MAIN
#PROGBAR
EndEnumeration


Procedure Main()
Protected iEvent, k
Protected iTopValue = 100 ; change this to try

If OpenWindow(#WIN_MAIN, 10, 10, 640, 480, "Main Window", #PB_Window_SystemMenu)

CompilerIf #DEFINE_FIX_ENABLED = 1

    ; you define min and max as usual, but include the top value in this macro
    ProgressBarGadget(#PROGBAR, 10,10, 600, 20, 1, VISTA_PROGBAR_FIX (iTopValue))
   
    For k = 1 To iTopValue                 
        SetVistaProgressBarValue (#PROGBAR, k)
        Delay(25)  ;  to simulate the processing time of each item       
    Next
    
CompilerElse
 
    ProgressBarGadget(#PROGBAR, 10,10, 600, 20, 1, iTopValue)
   
    For k = 1 To iTopValue                 
        SetGadgetState (#PROGBAR, k)
        Delay(25)  ;  to simulate the processing time of each item       
    Next

CompilerEndIf
   
    Delay(100)  ; at the end of the loop, to be on the safe side
                 
    FreeGadget(#PROGBAR) ; release the statusbar
     
    Repeat
        iEvent = WaitWindowEvent()       
    Until iEvent = #PB_Event_CloseWindow
   
EndIf

EndProcedure

Main()
EDIT: added a sample of the normal behaviour in case you haven't experienced it yet. See #DEFINE_FIX_ENABLED.

Re: Vista / Win7 progress bar realtime updating fix

Posted: Sat Dec 19, 2009 1:02 am
by SFSxOI
Thanks for the post luis. :)

But I don't understand > "All nice and well, but when you go smootly from 1 to 100 for example, half of the time the bar is still at 50%-75% when you are closing your pretty window. Not nice."

I'm not seeing that here on my Windows 7 Ultimate machines.

Re: Vista / Win7 progress bar realtime updating fix

Posted: Sat Dec 19, 2009 1:11 am
by luis
Hi, it does not happen always and everywhere, but happens a lot. I found many posts in various forums lamenting this behavior under vista/7.

I saw the problem on my win7 computer and inside a VM with windows 7. Enough to try to fix it!

Have you tried the snippet above setting #DEFINE_FIX_ENABLED = 0 ?

If you didn't notice yet good for you ! But remember this thread for future reference :)

If you give enough time to the gui, and you don't close the window with the progress bar, eventually it will catch up.

EDIT: found another old thread about this (I believe):
http://www.purebasic.fr/english/viewtopic.php?p=256855

EDIT: another link about this:
http://social.msdn.microsoft.com/Forums ... cae21e0b32

Re: Vista / Win7 progress bar realtime updating fix

Posted: Sat Dec 19, 2009 7:47 am
by chi
thanks luis! exactly what i was looking for :wink:

Re: Vista / Win7 progress bar realtime updating fix

Posted: Sat Dec 19, 2009 6:33 pm
by luis
Hi chi, the method have some shortcomings but it's the simplest way to accomplish this I have found.

According to this:
http://msdn.microsoft.com/en-us/library ... 85%29.aspx

there is not a style we can use to disable this under Aero....

If anyone discover a "clean" way to fix this mess please let us know (disabling themes for the specific gadget doesn't count) :wink: