Archived

This topic is now archived and is closed to further replies.

MFC Modal Dialog.

This topic is 5501 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a MFC program. When I do a lengthy task I want to display a modal dialog with nothing in it but a static text and a progressbar. So I call .DoModal(); but how do I know its initiated and where do I put the code? All I want to do is to call DoModal and it should show the window, do my process and then close again. This is driving me quite mad, ive been reading 12383 different Messages and tried all different On methods. But I cant find anything that is "Whenwindowiscreatedanddonecallthisroutine()" - Zorak - Neat Fella.

Share this post


Link to post
Share on other sites
OnInitDialog?

If you''re trying to do something from the main window after a DoModal that''s not going to happen. You''ll either have to make the dialog modal, or pre-load everything... once it''s up and modal your app is locked there until you return out of the dialog.

-fel

Share this post


Link to post
Share on other sites
You may create the dialog box anywhere. I recommend the view or main class. I assume you a multiple threads processing information. Thus, I would recommend the main class. Send messages to your main class to update the dialog box.

Share this post


Link to post
Share on other sites
quote:
Original post by kuphryn
Send messages to your main class to update the dialog box.

That won''t work, as a DoModal suspends the main app''s message queue until the modal dialog returns. What he could do is spawn the thread from the dialog and then establish protocol to communicate between the thread and the dialog. The dialog will know about the thread because it "owns" it, so can post messages to it. However, the thread doesn''t know about the dialog. One way to let the thread know it is interested is to have a message where it posts a reinterpreted pointer to itself and the thread registers that it has an "observer". The thread is then able to send any update messages to observers. Furthermore, good GUI design dictates that the user should be able to can the subtask, by hitting "cancel", so a cancel message should be forwarded onto the thread and it can clean itself up. Additionally, I''d say that any "OK" button should be disabled until the subtask is complete.

Share this post


Link to post
Share on other sites