inserting timer pauses into VC++, Ver 5.0

In my code written in MS VC++, Ver 5.0, I'm writing messages to the Dialog Box on the screen during program run.  The messages don't get displayed in time for status updates due to the code running so quickly.

How do I put a delay, wait, pause with a variable time in my code?

Thanks!

dgoernerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

abancroftCommented:
You can use Sleep() to suspend the current thread - but I'm not sure that's what you want to do.

Is the dialog box there to give status updates on a length operation? e.g. a status bar.
0
nietodCommented:
In windows, for this sort of thing it is usually best to create a timer using SetTimer() and then perform the appropriate acts when a WM_TIMER message is received.
0
NT_ProgrammerCommented:
Is your app single or multithreaded?

It sounds to me like it is single threaded.

If it is single threaded when you post a message to the dialog with an update (I assume via PostMessage( )) the message sits in the queue until (1) your function returns and goes back to the message loop or (2) you run a message pump.  Here's a simple message pump you can run in a single threaded app to allow the GUI to "catch up" when you are doing heavy processing:

void PumpMessage( void )
{
   MSG msg;
   while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
   {
      TranslateMessage( &msg );
      DispatchMessage( &msg );
   }
}

If your app is multithreaded and you are running a worker thread that is posting updates back to the GUI thread you can call Sleep( x ); every time you post an update message to the GUI where x represents the number of miliseconds you want the worker thread to stop for.  If you pass 0 it will cause the worker thread to relenquish the rest of its time slice.  If Sleep( 0 ) isn't enough for the GUI to catch up, use a higher number.

An alternative if your GUI is running slow because your worker thread(s) are eating up the CPU is to make the GUI thread a higher priority with SetThreadPriority( hThread, nPriority );  Or you could set the worker threads to a lower priority by the same function call.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dgoernerAuthor Commented:
First of all, thanks for answering my (seemingly simple) question.

My application is single-threaded.  I am not using PostMessage at all, and being a realtive "newcomer" to OOP, honestly hadn't even heard of that function.  I've written lots of C++ code in DOS, but only a few programs thus far in Win 98.

I will look into this funtinality, as it "sounds like" what I should be using all along!
0
NT_ProgrammerCommented:
I would recomend multithreading.  If you send an email with "CWinThread Worker Request" as the subject to NT.Programmer@home.com you will get it from me.  It goes over using CWinThread for your worker thread.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.