Introduction of member functions
1. Create ()
This function is required to create a progress bar that is not generated by dragging a progress bar control on a resource file.
2, SetRange ()
Sets the start and end values of the progress bar.
3, SetPos ()
Sets the current position of the progress bar.
4, OffsetPos ()
Move the progress bar some distance
5, SetStep ()
Set Step size
6, StepIt ()
Update location by step
Ii. examples
Example 1: Manually adding a control to the resource window Idc_progress1
CProgressCtrl *MYPROCTRL2 = (CProgressCtrl *) GetDlgItem (IDC_PROGRESS1);
Myproctrl2->setrange (0,100);
for (int i = 0;i<100;i++)
{
Myproctrl2->offsetpos (1); This code is equivalent to the next two sentences, the Fixed step 1 update display, the function can also be implemented as follows: Myproctrl2->setpos (i);
Myproctrl2->setstep (1);
Myproctrl2->stepit ();
Sleep (100);
}
Example 2: The resource window does not increase and the progress bar is generated directly from the code
CProgressCtrl Myproctrl;
CRect Rect,prorect;
GetClientRect (&rect);
prorect.left = rect.left + rect. Width ()/2-100;
prorect.top = rect.top + rect. Height ()/2-20;
prorect.right = Rect.right-rect. Width ()/2 +;
Prorect.bottom = Rect.bottom-rect. Height ()/2 +;
//ws_child| ws_visible| Pbs_smoothreverse
myproctrl.create (ws_visible,prorect,this,99);//create location, size
Myproctrl.setrange (0,100);
int i;
For (i = 0; i <; i++)
{
Myproctrl.offsetpos (1);
CString str;
Str. Format (_t ("%d%%"), i); Percentage
(GetDlgItem (IDC_STATIC1))->setwindowtext (str);
Sleep (+);
}
Better quality and more exciting articles see: http://blog.csdn.net/visualeleven/article/details/6165007
MFC progress bar CProgressCtrl