Solved

Using CProggresbar

Posted on 2000-03-11
7
196 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:nirkr
7 Comments
 
LVL 3

Expert Comment

by:ghimireniraj
Comment Utility
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
 
LVL 8

Expert Comment

by:VinExpert
Comment Utility
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
 
LVL 2

Expert Comment

by:abdij
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 2

Expert Comment

by:abdij
Comment Utility
abdij changed the proposed answer to a comment
0
 
LVL 2

Expert Comment

by:abdij
Comment Utility
Hi,
 If possible send ur code to abdij_b@hotmail.com. Lets see if we can fix it.

Bye
ABdij
0
 
LVL 3

Accepted Solution

by:
kulina earned 50 total points
Comment Utility
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
 
LVL 3

Expert Comment

by:kulina
Comment Utility
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

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now