Using CProggresbar

Hi,
I'm trying to use this control.
The problem i have is how to show the the precentage in the control?
please send me an example
nirkrAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
kulinaConnect With a Mentor Commented:
Try this logic:

CProgressCtrl progres;
CClientDC dc(this);
CRect rect;
rect.SetRect(10, 10, 210, 40); //example
char mesg[6];
progress.Create(WS_VISIBLE | PBS_SMOOTH
| WS_CHILD, rect, this, IDC_PROGRESS1);
progress.SetRange( 0, 100 );
progress.SetStep( 1 );

for (int i=0; i<100; i++){
      progress.StepIt();
      sprintf(mesg, "%d %%", i+1);
      dc.DrawText(CString(mesg),
      CRect rect, DT_CENTER );
      Sleep(20);
}
....where mesg will contain percentage amount and rect is a Progress Bar rectangle.
But make sure to SetRange from 1 to 100
for progress and percentage to be consistent.
0
 
ghimirenirajCommented:
well, its like this,


CProgressCtrl * pBar=(CProgressCtrl*)GetDlgItem(IDC_var_name);

IDC_var_name is the name you give to the progress bar in its property.


int position;
pBar->SetRange(0,100);
//calculate your percentage position
//lets say its 50
position=50;
pBar->SetPos(position);


That  will do the job


ghimireniraj


0
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

Follow the steps.
1. Add the progeass bar control into dialog template and give the ID as ID_PROGRESS.
2. Add the control variable to it using class wizard say m_Progress of type CProgressCtrl
3. Then Initialise the progress bar as
m_Progress.SetRange(Min, Max);
m_Progress.SetPos(0);
m_Progress.SetStep(1);
4. Then to increament it use
m_Progress.StepIt();

Thats it. If U want the sample, give me Ur mail ID, I will send it to U

Cheers,
VinExpert.
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
abdijCommented:
Hi,

 Here is how u can use it.


I have used the OnOk button of the window to start a time to update the progress bar.

m_ctrlProgressBar id the control of the Progress bar mapped through Calss wizard.

Here is the code of the OnOk and Timer function

void CProgressDlg::OnOK()
{
      // initially set the range
      m_ctrlProgressBar.SetRange(0,100);
      // set the position
      m_ctrlProgressBar.SetPos(0);

      // i start a time to update the progress bar.
      // u can use an event mechanism to get the progree
      // for eg: if there are 10 things to do in another thread
      // set an event after each job done and manipulate the
      // progree bar
      SetTimer(1000,1000,0);
}


void CProgressDlg::OnTimer(UINT nIDEvent)
{

      // inti position static thatis
      static int nPos = 0;

      // the progree bar is full
      if(nPos > 100)
      {
            // OK
            CDialog::OnOK();
            return;
      }

      // update the new postion
      nPos +=10;
      //  set the position on the progress bar
      m_ctrlProgressBar.SetPos(nPos);
      // not neede i use it to emphasize the effect !!!!
      Sleep(100);
      
      CDialog::OnTimer(nIDEvent);
}


I have used percentage as 10. U can use any resoultion ( min 1 i think).

The manipulation of % depends on what u need to do.

Hope this helps

Bye
Abdij
0
 
abdijCommented:
abdij changed the proposed answer to a comment
0
 
abdijCommented:
Hi,
 If possible send ur code to abdij_b@hotmail.com. Lets see if we can fix it.

Bye
ABdij
0
 
kulinaCommented:
Let me just make this code a bit more readable, since it looks awfull in my proposed answer.

CProgressCtrl progres;
CClientDC dc(this);
CRect rect;
rect.SetRect(10, 10, 210, 40); //example
char mesg[6];
progress.Create(WS_VISIBLE | PBS_SMOOTH | WS_CHILD, rect, this, IDC_PROGRESS1);
progress.SetRange( 0, 100 );
progress.SetStep( 1 );

for (int i=0; i<100; i++){
      progress.StepIt();
      sprintf(mesg, "%d %%", i+1);
      dc.DrawText(CString(mesg), CRect rect, DT_CENTER );
      Sleep(20);
}
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.