Re: (C) Simulated progress bar

From: B. v Ingen Schenau (bart_at_ingen.ddns.info)
Date: 11/14/04


Date: Sun, 14 Nov 2004 12:31:41 +0100

Paul Fedorenko wrote:

> My friend, the psychologist, who asked me to put together a little
> program for him has asked me if I could get the program to pause for a
> second between turns and to display a progress indicator to make it
> look like the program's running some calculations in the background.
>
> I'm thinking the progress bar would be fairly straight-forward...
> Just a for loop, set up to display a bunch of hashmarks or ASCII block
> characters
> one at a time... How would I get it to take a second or two to run
> through
> the loop? That sounds like an awfully long time.

If you can use non-standard extension, then ask in a group for your OS
what call the OS provides to let your program wait for some time.

If you can only use standard C functions, you can write a busy-loop like
this:

#define WAITING_TIME 2 /* seconds */
time_t start = time(NULL);
for (double elapsed = difftime(start, time(NULL));
     elapsed < WAITING_TIME;
     elapsed = difftime(start, time(NULL)))
{
  /* show progress bar (use elapsed to determine if a new segment can be
shown */
}

Bart v Ingen Schenau

-- 
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://www.eskimo.com/~scs/C-faq/top.html
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/


Relevant Pages

  • ProgressBar assist needed
    ... I am reading text file of unknown number of records into a UDT array, ... I am current using a counter in the loop to display the record count on ... progress bar. ...
    (microsoft.public.vb.general.discussion)
  • Re: visual basic 6 progress bar?
    ... What I'm trying to do is display a progress bar for 1 Do Until loop within my program. ... When I put the progress bar code on the out side of the loop, it ran the whole Do Until loop first and then displayed the progress bar filling up afterward: ...
    (microsoft.public.vb.controls)
  • Re: Word 2003 document icons not displaying
    ... Intermediate User's Guide to Microsoft Word (supplemented version of ... See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome! ... Access display properly. ... I don't know if this might be a factor but I'm usning Windows 2000 ...
    (microsoft.public.word.docmanagement)
  • RE: Progress bar on composite control
    ... do postback to do some server-side processing which may take some time. ... such progress bar displaying should be done through ... My suggestion is you display the progress bar before your control ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Executing a program while displaying a model window
    ... I display the form with ShowDialogand is inside this form where I create ... time a file is copied the progress bar is updated with the name of the file ... public delegate void ProcessedFileHandler(); // I use this delegate to send ... > progress bar window until the scanning is complete or the user clicks ...
    (microsoft.public.dotnet.languages.csharp)