Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Implement Progress Bar (http://www.go4expert.com/forums/implement-progress-bar-t2532/)

priyapai 12Jan2007 16:52

Implement Progress Bar
 
Hi Experts,

I need to implement a progress bar.

I have the Bar dimensions available. There r some function calls(APIs) available to me to create the Rectangular Bar, Fill in the Colour, clear the Rectangular bar, etc.

I need to implement a function which looks like:

void Progress_bar(int x1. int y1, int x2, int y2,int Download_percentage );

wer (x1,y1) ->co-ordinates of Top left corner of Progress Bar
(x2,y2) ->co-ordinates of Bottom Right corner of Progress Bar
Download_percentage -> information which need to be mapped on the progress Bar.
This wil vary between 0-100.

Can any1 share their idea on implementing this in an Efficient way....

Waiting for responce..

ever_thus 12Jan2007 20:09

Re: Implement Progress Bar
 
Are you implementing this in Windows. I ask because a progress bar is a graphic and therefore OS dependent.

ever_thus 12Jan2007 21:27

Re: Implement Progress Bar
 
I misunderstood your question. Do you want to know how to avoid inefficiencies in your progress bar.

The best way is to use a solution someone elese has created. The windows shell has a built in progress bar control called IProgressDialog. Start the progress bar window and call Setprogress after each operation has been completed.

More information here

priyapai 15Jan2007 09:36

Re: Implement Progress Bar
 
m creating this funtinaliyt for mobile Application.

The scnario is, when a file(Video/Audio) is getting played i need to show the user its playback progress.

The playback percentage will be provided to me , which may vary between the range 0-100.
What m looking for is the logic to implement this.

The width of the progress bar is unknown.

ever_thus 16Jan2007 08:18

Re: Implement Progress Bar
 
Is the mobile application Windows CE. In that case I highly recommend you use the class I provided. I unfortunately have no experience with graphics programming outside of Win32.

priyapai 16Jan2007 10:46

Re: Implement Progress Bar
 
Hey even_thus, m using C.

Also i have to implement the Progress Bar using some prdefined API's ( like Draw_rect(), fillcolour_rect() , etc)

I am only looking for an efficient logic to implement the Progress Bar.

ever_thus 16Jan2007 20:08

Re: Implement Progress Bar
 
Code:

//all globals. They don't change so there's no need to keep recopying them
int x1. int y1, int x2, int y2;
int progress_length = x2 - x1;
RECT rect;
rect.left = x1;
rect.top = y1;
rect.bottom = y2;

void Progress_bar(int Download_percentage ){
    rect.right = x1 + progress_length * Download_percentage;  //assuming Download_percentage is a fraction
    HDC hdc = GetDC (hwnd_your_progress_bar);
    HBRUSH brush = GetSysColorBrush (COLOR_HIGHLIGHT);  //gray
    FillRect (hdc, rect, brush);
}

But once again, this is only if you're programming in Windows.

BTW, you can call COM objects (which is what IProgressDialog is) from any language, including C. See here (end of part 2)

ever_thus 16Jan2007 20:21

Re: Implement Progress Bar
 
I posted the reply in a hurry. Here are some modifications.

Make hdc and hbrush global too. Or better, make all those global variables static in Progress_bar or, if you can, local to the function that calls Progress_bar. Globals are normally a bad idea.

Finally, when you're done with the progress bar call:
Code:

ReleaseDC (hwnd_your_progress_bar, hdc)


All times are GMT +5.5. The time now is 18:54.