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()