Solved

Using CProggresbar

Posted on 2000-03-11
7
216 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
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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to know only "File created" with EventLog 3 34
FizzBuzz challenge 9 80
mapAB Challlenge 35 144
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 545
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

776 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