Solved

Using CProggresbar

Posted on 2000-03-11
7
233 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 3

Expert Comment

by:ghimireniraj
ID: 2610174
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
ID: 2611038
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
ID: 2611121
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:abdij
ID: 2611125
abdij changed the proposed answer to a comment
0
 
LVL 2

Expert Comment

by:abdij
ID: 2611130
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
ID: 2654525
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
ID: 2654566
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

691 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