Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ProgressBar lag when setting position with PBM_SETPOS [duplicate]

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.

like image 776
c00000fd Avatar asked Mar 18 '14 03:03

c00000fd


1 Answers

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);
}
like image 131
Remy Lebeau Avatar answered Nov 15 '22 06:11

Remy Lebeau