Modal Dialog needs to block all windows

My app has multiple CFrameWnd windows.
They use the WS_OVERLAPPEDWINDOW style.
Their parent is the main window.
The problem is when one of them brings up a modal dialog,
the other windows are still active.
I assume separate threads are running, one per window.
Is there an easy way to cause the other threads to block?
I'd like to avoid designing something using synch objects.
I'm looking for a way to do it from the thread that is
bringing up the dialog.
I just want the modal dialog to be modal for the whole
Who is Participating?
Tommy HuiConnect With a Mentor EngineerCommented:
What you will need to do is enumerate through your process's window and disable everything except your dialog. You can use EnumWindows() to enumerate through all of the windows. Then use GetWindowThreadProcessId() to retrieve and process id that created that window. Compare it with yours (retrieved with GetCurrentProcessId()). If they match, then check to see if it is your dialog. If it isn't, then disable it.

You will need to enable the windows again when you're done with the dialog.
Make it SYSTEM Modal
If you make the parent of your modal dialog box, the main window not the frame window, then that modal dialog box will become modal for you aplication and not for the frame. you must have noticed that "Help About" dialog box is modal for all the aplication.

Somehting like this...

void CChildFrame::OnHelpTest()
      CTestDlg dlg (AfxGetMainWnd ());
      dlg.DoModal ();
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

I tested out your problem, but I used CMDIChildWindow as my base class instead.  When I displayed a modal dialog it was modal throughout the application.  Chances are you are only using one thread, so the modal dialog should be modal throughout the app.  Let me know if you can use a an MDI child window instead of CFrameWnd.
don't make it system modal, that's more modality than you want -- you don't want to take away from other apps' functions; that's bad style if nothing else
bwilhelmAuthor Commented:
I do not want a system-modal dialog, only application-modal.

I tried the AfxGetMainWnd() as the parent, but that did not help.

More specific info on my problem:
My main window is a CMDIFrameWnd.
My second window is a CFrameWnd whose parent is the main window.
The 2nd window is a WS_OVERLAPPEDWINDOW.
(not embedded inside the main frame)
The modal dialog (based on CDialog) also has the main window as its parent.
The 2nd window is still alive/active while the modal dialog is up.
ex: can get focus, receives all events...

Again, I would recommend using CMDIChildWnd instead of CFrameWnd, as the functionality you request is built-in...  I'll take a look at some ways around this though.  What do you need CFrameWnd for that CMDIChildFrm can't do?
bwilhelmAuthor Commented:
The EnumWindows() solution does work.
It keeps me from having to know which CFrameWnd's are in my process,
which is desirable.
Unfortunately I still need to add this hack on a per-dialog basis.
It would be nice if that was not necessary.
Thanks for the help!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.