4. 现在,是使用它的时候了:
CMainFrame::OnSomeLongProcess()
{
RECT MyRect;
// substitute 4 with the zero-based index of your status bar pane.
// For example, if you put your pane first in the indicators array,
// you'd put 0, second you'd put 1, etc.
m_wndStatusBar.GetItemRect(4, &MyRect);
if (m_bCreated == FALSE)
{
//Create the progress control
m_Progress.Create(WS_VISIBLE|WS_CHILD, MyRect, &wndStatusBar, 1);
m_Progress.SetRange(0,100); //Set the range to between 0 and 100
m_Progress.SetStep(1); // Set the step amount
m_bCreated = TRUE;
}
// Now we'd simulate a long process:
for (int I = 0; I <100; I++) { Sleep(20); m_Progress.StepIt(); } }
在进度条创建时,如果窗口重新定位,需要重载OnSize函数使之正确重定位:
void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
CMDIFrameWnd::OnSize(nType, cx, cy);
RECT rc;
m_wndStatusBar.GetItemRect(4, &rc);
// Reposition the progress control correctly!
m_Progress.SetWindowPos(&wndTop, rc.left, rc.top, rc.right - rc.left,
rc.bottom - rc.top, 0);
}