MFC progress bar (cprogressctrl) re-painting
First View a chart :
Create a class that inherits from cprogressctrl and add the onpaint message processing function.CodeAs follows:
Void Cnewprogress: onpaint () {cpaintdc DC ( This ); Cbrush backgroundbrush; backgroundbrush. createsolidbrush (RGB ( 255 , 0 , 0 ); Cbrush forebrush; forebrush. createsolidbrush (RGB ( 100 , 255 , 0 ); Crect R; This -> Getclientrect (R ); Double With = R. Width (); Int Min, Max; This ->Getrange (Min, max ); Int Pos = This -> Getpos (); Double Unit = ( Double ) R. Width ()/(max- Min); DC. fillrect (r, & Backgroundbrush); R. Right = POS * Unit; DC. fillrect (r, & Forebrush );}
In this way, cprogressctrl is re-painted.
if you want to add an onlbuttondown message to the progress bar and click it with the left mouse button to the specified position, you must add the onlbuttondown message processing function. The Code is as follows:
void cnewprogress: onlbuttondown (uint nflags, cpoint point) {crect R; This -> getclientrect (r); double with = r. width (); int min, max; This -> getrange (Min, max); double unit = ( double ) (max-min)/R. width (); /// int Pos = point. x * unit; This -> setpos (POS); cprogressctrl: onlbuttondown (nflags, point );}