I have a simple C++/MFC dialog that has a progress bar control in it. I set its position with the PBM_SETPOS message, or MFC's:
//CProgressCtrl myCtrl;
myCtrl.SetPos(position);
It works fine, except when I need this position to grow fast, it seems to lag behind.
Is there any way to remove this lag?
PS. I tried my app on older version of Windows (with classic visual styles) and this lag is not present there.
The lag is by design when visual styles are enabled to provide a smoother animated experience to the user. This is a little documented but well-known issue. You cannot remove the lag, but you can work around it. The lag only happens when increasing the position but not when decreasing it. Call SetPos(position+1)
followed by SetPos(position)
, and the bar will jump immediately. The tricky part comes at the end. When you want to set the position to the max value, you have to first increase the max value +1, then set the desired position +1, then set the real position, then finally restore the original max value. That will allow the progressbar to fill the entire bar.
int lower, upper;
myCtrl.GetRange(lower, upper);
if (position >= upper)
{
myCtrl.SetRange(lower, upper+1);
myCtrl.SetPos(upper+1);
myCtrl.SetPos(upper);
myCtrl.SetRange(lower, upper);
}
else
{
myCtrl.SetPos(position+1);
myCtrl.SetPos(position);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With