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..
|
Contributor
|
|
| 12Jan2007,20:09 | #2 |
|
Are you implementing this in Windows. I ask because a progress bar is a graphic and therefore OS dependent.
|
|
Contributor
|
|
| 12Jan2007,21:27 | #3 |
|
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 |
|
Go4Expert Member
|
|
| 15Jan2007,09:36 | #4 |
|
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. |
|
Contributor
|
|
| 16Jan2007,08:18 | #5 |
|
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.
|
|
Go4Expert Member
|
|
| 16Jan2007,10:46 | #6 |
|
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. |
|
Contributor
|
|
| 16Jan2007,20:08 | #7 |
|
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);
}
BTW, you can call COM objects (which is what IProgressDialog is) from any language, including C. See here (end of part 2) |
|
Contributor
|
|
| 16Jan2007,20:21 | #8 |
|
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) |
