My program occasionally has to do a little bit of heavy lifting processing wise, and I'd like a function that says something to the effect of
Now 40% complete...
Now 83% complete...
etc.
I have the function written and it works, but it calls so fast that the screen just fills up with
Now 1%
Now 2%
Now 3%
etc.
What I would like is the function to only be called once per second. HOWEVER what I DON'T want to do is use the sleep() or a wait() function because that will stop the programming from running altogether. I want something more along the lines of...
bool onSecond() // returns if clock is on a second
int ms = 100; //milliseconds remaining
while(...)
{
Sleep(10);
//Update window, message etc...
ms = ms - 10;
if (ms <= 0)//Time out
{
percent = percent + 1;
Display();
ms = 100;
}
Also you may try the another method : Create a calculation thread and do the process bar code, instead of sleeping the main thread. That's better.
Edit : If you want to use the function "settimer", specify and handle the message WM_TIMER
Your original idea was a good one, and its not hard to do. You just need to use a seperate thread of excution for the processing. You can look at the CreateThread() Api function. If you don't try it you won't learn anything. I don't have time to post code now, but perhaps late tomorrow.