Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Modal Dialog needs to block all windows

Posted on 1999-06-25
Medium Priority
Last Modified: 2013-11-20
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
Question by:bwilhelm
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 1307930
Make it SYSTEM Modal
LVL 23

Expert Comment

ID: 1307931
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 ();

Expert Comment

ID: 1307932
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.
Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.


Expert Comment

ID: 1307933
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

Author Comment

ID: 1307934
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...


Expert Comment

ID: 1307935
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?
LVL 15

Accepted Solution

Tommy Hui earned 600 total points
ID: 1307936
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.

Author Comment

ID: 1307937
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!


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question