We help IT Professionals succeed at work.

MFC Dialog


I have MFC dialog  that has Next and Back buttons on it. It also has 4 child dialogs out of which one has a progress control on it.

When this particular dialog appears, I would like to start a progress bar and keep changing the static control above it with messages like "Initializing...", "installation started", "Finished" etc.

As I go on changing the text on the static control, parent dialog kind of hangs. Next & Back buttons partially appear (they don't get repainted properly). Once the progress function is finished, everything comes to normal state.

Can anybody tell me how should I show progress on a static control keeping my parent form movable, re-sizable etc.  
Watch Question

Probably, you perform a heavy operation from the OnInitDialog on this page. And do not update the window. Create a thread and perform this operation in this thread. Send notifications from this thread to the dialog.

Simple Multithreading in Visual C++
AndyAinscowFreelance programmer / Consultant
Call this function in your loop where you update the progress control

void DoEvents()
    MSG msg;  
    while ( ::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE ) )
This is like managing applications Cache Management. Do not put so many thing (E.G. UI Customisation, Reloading the other views, loading sub windows ete.) to your Initdialog functions or any common method which is used by your application. This is the only reason that your application is in astate of temporary hung.
Launch your child dialogs as a Modeless dialog boxes instead of Modal. This allows you to have your child dialog work separately as well as let you to interact with the parent dialog. Regarding the hung, try putting Sleep(1000) inside the loop where you are incrementing the progress of a progress bar. I guess the temporary hung is because you are making the processor to run your loop very fast. Sleep allows the processor to concentrate on other threads and hence there will be no hung.
If you like to install something use InnoSetup and you will not spend a lot of time by reinventing the wheel.


kind regards
There are good and bad answers here.  The one by AndyAinscow is good.  The one suggesting using Sleep() is bad.  (Almost all uses of Sleep() are kludges and in this case I do not believe it will work.)
I've requested that this question be deleted for the following reason:

No comment has been added to this question in more than 21 days, so it is now classified as abandoned and is now flagged for deletion.

If there is a valid solution, please OBJECT and indicate the comments that are, or would otherwise lead to, a solution.

Use the specific format http:#axxxxxxxx for comment ID(s).

Also, please don't object simply because the author did not respond to your comment. While we understand this is frustrating, unfortunately we cannot force the author to return to the question. Unless you feel you have presented a valid, verifiable solution we'll simply delete the question.

Experts-Exchange Auto Deleter
AndyAinscowFreelance programmer / Consultant

Split between
both methods will work.  The second is simpler to implement but the first is 'better' overall.