Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using progressbar

Status
Not open for further replies.

Leibnitz

Programmer
Apr 6, 2001
393
CA
How can i use a progressbar that i have created from VC++
resource editor ?
Any tips will be very apreciated.
 
Here's an example. I put the progress bar and a static textbox on a dialog:
CProgressCtrl m_SaveProgress;
CStatic m_SaveText;

and added these other required members:
int m_iCurrentPosition;
int m_iStep;
int m_iUpperLimit;

Here's part of the cpp file for the progress bar object:

Code:
// In the progress bar object, initialize the "upper limit" value
// and the "step" value.

void CProgress::SetParameters(int iUpperLimit)
{
  m_iCurrentPosition = 0;
  m_iUpperLimit = iUpperLimit;

  if (iUpperLimit >= 100) {
    m_iStep = (int)(iUpperLimit * .01 + .5);
  }
  else {
    m_iStep = 1;
  }

  m_SaveProgress.SetPos(0);
  m_SaveProgress.SetStep(m_iStep);
  m_SaveProgress.SetRange32(0, iUpperLimit);
}


// within the work loop in your main code, call the increment function each time.

void CProgress::Increment()
{
  m_iCurrentPosition++;

  // only update the progress bar display at "step" value increments
  // or when the upper limit is reached

  if ((m_iCurrentPosition % m_iStep == 0) || (m_iCurrentPosition >= m_iUpperLimit)) {

    m_SaveProgress.StepIt();

    int iProgress = (m_SaveProgress.GetPos() * 100) / m_iUpperLimit;

    CString sText;
    sText.Format("%3i", iProgress);

    m_SaveText.SetWindowText(sText);
  }
}

// hope this helps!
;-)
 
Thanks this was great,but is there any way to do same thing but without using MFC ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top