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?


Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

NT_ProgrammerConnect With a Mentor Commented:
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.
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.
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.
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!
I would recomend multithreading.  If you send an email with "CWinThread Worker Request" as the subject to you will get it from me.  It goes over using CWinThread for your worker thread.
All Courses

From novice to tech pro — start learning today.