Click here to Skip to main content
Click here to Skip to main content

The singular non-modality of MFC modal dialogs

By , 6 Apr 2003
 

Introduction

For the non-programmer, modal dialog boxes are those that refuse to go away till you dismiss them, which is usually done by clicking on the OK or Cancel buttons. For the programmer (the non-VB ones anyway), modal dialog boxes are those that disable their immediate parent window before they are created, and enable their parent window when they are closed. Thus the essence of a modal dialog is that you cannot do anything to the parent window till you close the modal dialog. Modeless dialogs are comparatively more polite and less fussy in that they do not insist on being dismissed to allow you to access their parent windows. I trust that by now, any infinitesimal doubts any of you might have had regarding the modality of a dialog has been absolutely eradicated.

MFC has a class called CDialog which is a CWnd derived class that is specifically used for the creation and display of dialog boxes on screen - both modal and modeless dialogs are supported. Modeless dialogs are created using Create() and you have to destroy them on your own using DestroyWindow() and they behave just like any normal modeless window. Modal dialogs are created and shown using the formidable DoModal() method of the CDialog class. And you close a modal dialog by calling EndDialog() or alternatively by calling OnOK() or OnCancel() both of which internally call EndDialog(). The CDialog::EndDialog method will call the EndDialog Win32 API function which is defined in user32.dll. EndDialog (the API function) will not immediately close the dialog, rather it will set a flag which will instruct the message queue to exit the loop, destroy the dialog window and enable the parent window. So far so good; everything seems so peaceful and serene, and the little birds in the tree across the yard are tweeting in a beautiful voice.

The non-modality factor

The Win32 API supports various dialog box related functions which include functions for creating both modeless and modal dialogs. There are the CreateDialogXXX set of functions like CreateDialog, CreateDialogIndirect etc. which are used to create modeless dialog boxes and the DialogBoxXXX set of functions like DialogBox, DialogBoxIndirect etc. which create modal dialogs. And as mentioned in the previous section there is also the EndDialog function which is used to end modal dialogs and only modal dialogs. Modeless dialogs must be terminated by calling DestroyWindow directly. The basic reason why you should not attempt to use EndDialog on a modeless dialog is that modeless dialogs do not have their own modal message loop nor do they disable their parent window, which basically nullifies the utility value of using EndDialog on them.

Alright, now this is what will give you a solid kick - MFC CDialog based modal dialogs are not modal dialogs. Just in case you did not read that right the first time, here it goes again - MFC CDialog based modal dialogs are not modal dialogs. I would have said it a third time but the fear of being termed a parrot thwarts me from doing so. Open dlgcore.cpp and examine the source code and you'll see that this astonishing statement is true. The MFC CDialog class uses the CreateDialogIndirect API function to create a pseudo-modal dialog and if you look up CreateDialogIndirect on MSDN you'll see that it is used to create a modeless dialog. The MFC command routing mechanism uses a combination of message maps and virtual functions to achieve what it does and a true modal dialog will totally wreck this mechanism because then the modal message loop is controlled outside the scope of the MFC command routing machinery. Thus the developers had no choice but to creat a pseudo-modal modeless dialog and then document it very intensely as a modal dialog.

Basically these are the summarized steps that are done when a pseudo-modal dialog is created via CDialog::DoModal -

  • A boolean flag bEnableParent is set to FALSE
  • If the parent window is enabled, then it is disabled and bEnableParent is set to TRUE
  • The dialog box is created using CreateDialogIndirect
  • A message pump is maintained using CWnd::RunModalLoop
  • Once the modal loop exits (when CDialog::EndDialog is called) the parent window is enabled if bEnableParent is TRUE
  • The dialog window is destroyed by calling DestroyWindow
  • And DoModal returns the argument passed to EndDialog

As you can see the developers have taken great pains to ensure that the pseudo-modal dialogs behave exactly as modal dialogs are supposed to. They have even tried to accommodate for unusual scenarios where there might be two modal dialogs both having the same parent - this is where the bEnableParent comes into play. Thus when the second modal dialog comes up, it will not set bEnableParent to TRUE because the parent window is already disabled. Thus when it is dismissed it will not enable the parent window which is exactly what is needed because another dialog modal to the same parent window is still active on screen.

EndDialog - a tiny flaw

As mentioned a couple of times already in this chapter, modal dialogs are dismissed using EndDialog. Let's see what EndDialog looks like (for those interested, it is defined in dlgcore.cpp)

void CDialog::EndDialog(int nResult)
{
    ASSERT(::IsWindow(m_hWnd));

    if (m_nFlags & (WF_MODALLOOP|WF_CONTINUEMODAL))
        EndModalLoop(nResult);

    ::EndDialog(m_hWnd, nResult);
}

CWnd::EndModalLoop is called to exit the message loop maintained by CWnd::RunModalLoop which is quite fine and then the EndDialog API function is called to terminate the modal dialog. This is also fine and Hey, hey, hey, just wait a cotton picking minute there!!!! The EndDialog API function is to be used only to close modal dialogs, but here we are attempting to use it to close a pseudo-modal dialog which is actually nothing but a modeless dialog disguised to reflect a modality it does not truly possess. [stunned silence...] Well, after that initial shock, let's all relax a bit. After all it's not the end of the world and EndDialog is not really a very harmful function call; it will only attempt to end a non-existent modal message loop and will enable the parent window of the dialog window. The former attempt will fail obviously and the latter attempt will just do something which we would have done anyway on our own, because the moment the pseudo-modal pump exits, DoModal will re-enable the parent window. So, is everything well and good, are the birds chirping peacefully once again?

The bug

Remember all that bEnableParent stuff we discussed a couple of paragraphs earlier, and how I mentioned how this flag is used to make sure that when multiple modal dialogs exist together that have the same parent window, this flag prevents the premature enabling of the parent window when one of the modal dialog siblings are dismissed? Well guess what? The careless programmer at Microsoft who coded this particular function had just rendered all those precautionary measures totally null and void. Because now any MFC modal dialog that is closed using EndDialog (which also means OnOK and OnCancel because those functions will internally call EndDialog) will enable it's parent window irrespective of what value bEnableParent holds. This basically means if you have two or more MFC modal dialogs which have the same parent window, then the moment you dismiss any one of those modal dialogs, all the other modal dialogs will lose their modality because now the parent window has been re-enabled.

Steps to reproduce this bug

  • Create an MFC dialog based application
  • Add a new dialog to it and associate a class with it called CChildDialog
  • Set two timers in the OnInitDialog method of the main dialog :-
  • SetTimer(1000,1000,NULL);	
    SetTimer(2000,2000,NULL);
  • Bring up a pseudo-modal dialog each, in the timer handler :-
  • void CModalDemoDlg::OnTimer(UINT nIDEvent)
    {
        KillTimer(nIDEvent);
        CChildDialog dlg(this);
        dlg.DoModal();
    
        CDialog::OnTimer(nIDEvent);
    }
  • Run the program and wait 2 seconds by which time you will have the main dialog and two modal child dialogs
  • Try to access the main dialog and you will be unable to do so because of the presence of the two modal dialogs
  • Now dismiss one of the child dialogs using the OK or the Cancel button
  • Now try to access the main dialog and you'll see to your astonishment that you will be able to do so, despite the presence of a modal dialog on screen

The project I have attached was created using VC++.NET 2003 Final Beta and I apologize to all those of you who do not have that version. But following the above mentioned steps shouldn't take you more than a few minutes at most. What is so amazing is that this bug has gone unnoticed through several versions of MFC. I checked as far back as VC++ 6 and that has the exact same problem too. As far as I see it, all someone's got to do is to comment out or delete the call to the EndDialog API call. I am guessing that what happened was this - the MFC developers were so much used to calling the native API equivalents from their wrapper functions (for example they would call the MessageBox API from inside CWnd::Messagebox) that someone must have automatically typed in that line without thinking and the QA guys must also have overlooked this error. And this problem remained mostly unknown because it was a very rare situation for a program to have a multi-modal window architecture where several modal dialog windows have the same parent window.

Work-around

Okay, so until Microsoft corrects this bug, what we could do (other than having to correct the MFC code and recompile MFC) is to override the OK and Cancel button handlers and to use this code instead of the default :-

{
    if (m_nFlags & (WF_MODALLOOP|WF_CONTINUEMODAL))
        EndModalLoop(IDOK); // or IDCANCEL
}

Notice how we are not calling the base class (if we do then ::EndDialog(...) gets called and all our efforts are wasted). If you want to exit the modal dialog in a place outside the OK/Cancel button handlers you should use the same code except that you might want to return a different value (like perhaps IDYES for example).

Conclusion

For all I know I might be the biggest jack-ass in town and there might be a perfectly legitimate reason for this matter, but something tells me that, that is a very remote contingency. By the way I'd like to thank Shog9 for sending me the VC++ 6 version of dlgcore.cpp at a rather late hour of the night (which to him is the equivalent of noon for most of us). I'd also like to explicitly mention here that this article is by no means an attempt to mock the amazing set of Microsoft programmers who developed the MFC library.

Version History

  • April 5 2003 - Article first published
  • April 7 2003 - Article updated with Work-around to the problem

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)

About the Author

Nish Sivakumar
United States United States
Member
Nish is a real nice guy who has been writing code since 1990 when he first got his hands on an 8088 with 640 KB RAM. Originally from sunny Trivandrum in India, he has been living in various places over the past few years and often thinks it’s time he settled down somewhere.
 
Nish has been a Microsoft Visual C++ MVP since October, 2002 - awfully nice of Microsoft, he thinks. He maintains an MVP tips and tricks web site - www.voidnish.com where you can find a consolidated list of his articles, writings and ideas on VC++, MFC, .NET and C++/CLI. Oh, and you might want to check out his blog on C++/CLI, MFC, .NET and a lot of other stuff - blog.voidnish.com.
 
Nish loves reading Science Fiction, P G Wodehouse and Agatha Christie, and also fancies himself to be a decent writer of sorts. He has authored a romantic comedy Summer Love and Some more Cricket as well as a programming book – Extending MFC applications with the .NET Framework.
 
Nish's latest book C++/CLI in Action published by Manning Publications is now available for purchase. You can read more about the book on his blog.
 
Despite his wife's attempts to get him into cooking, his best effort so far has been a badly done omelette. Some day, he hopes to be a good cook, and to cook a tasty dinner for his wife.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
AnswerSlight Correction for Modeless CDialog's [modified]memberMember 445110530 Nov '09 - 11:32 
This is the code I would recommend for the CDialog::EndDialog function.
   if (m_nFlags & (WF_MODALLOOP|WF_CONTINUEMODAL)) {
      EndModalLoop(nResult);
   }
 
   if(!m_inDoModal) { // this switch is set in our DoModal()
      VERIFY(::DestroyWindow(m_hWnd));
   }
Consider the following code that creates a modeless CDialog for notification (non-blocking). It may not be ideal, but it is legal. But what happens when the user clicks the IDOK button on this dialog? ... nothing. Because OnOK called EndModalLoop when no modal loop was running. We actually need to destroy the window when IDOK or IDCANCEL occur if not in a modal loop.
if(IsWindow(m_dlg.GetSafeHwnd())) {
   m_dlg.DestroyWindow();
}
 
m_dlg.setText("This is a lockout notification.  Finish your work and close the program.");
m_dlg.Create(IDD_LOCKOUT);
m_dlg.ShowWindow(SW_SHOWNOACTIVATE);
m_dlg.SetWindowPos(&wndTopMost  , 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
m_dlg.SetWindowPos(&wndNoTopMost, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOOWNERZORDER);
 
Dang! Still not quite right. -Edited-
 
modified on Friday, December 4, 2009 9:15 AM

GeneralAccess violation if parent window is closed before MFC CDialog-based modal dialog is closedmemberdoroboy20 Mar '08 - 22:54 
I have an access violation if I close parent window before the MFC CDialog-based modal dialog is closed.
I close the parent window using OnTimer. The application must close itself automatically and quickly even if any MFC CDialog-based modal dialog is being showed.
 
The access violation occurred in DLGCORE.CPP.
 
int CDialog::DoModal()
{
...
if (bEnableParent)
::EnableWindow(hWndParent, TRUE); // access violation because the hWndParent was NULL indeed.
if (hWndParent != NULL && ::GetActiveWindow() == m_hWnd)
::SetActiveWindow(hWndParent); // access violation because the hWndParent was NULL indeed.
...
}
 
Can I close the parent window when the MFC CDialog-based modal dialog is being showed? What is the correct way?
GeneralRe: Access violation if parent window is closed before MFC CDialog-based modal dialog is closedmemberMember 445110530 Nov '09 - 11:34 
You might look at using GetSafeOwner or GetLastActivePopup to close the windows in order rather than closing the parent first. That's my best guess. It will be hard to close a parent window before a child without having errors in CDialog.
GeneralWindow or Dialog with Desktop as parentmemberMoti@IT22 Jun '07 - 3:00 
Hi Nishant
Thanks for a nice article.
But I have one problem, I want to create a window or dialog which has desktop window as parent, So that If this window is active it should not allow to access desktop items.
How can I do this?
 
Motiram Patil,
Software Engineer.
Question"Enter" and "ESC" Keys could dismiss a modal dialog, anyway to prevent this?memberSstar7 Aug '06 - 18:23 
Press "Enter" key and "ESC" key would dismiss a modal dialog. These two key down events cannot not be captured and processed by the modal Dialog as the dialog will be immediately dismissed when user press the two keys.
 
Is there any good way to prevent this from happening in a dialog derived from CDIALOG?
 
D'Oh! | :doh:
AnswerRe: "Enter" and "ESC" Keys could dismiss a modal dialog, anyway to prevent this?memberlzinggl16 Oct '06 - 0:55 
You have to implement an OnOK and OnCancel - Handler. OK and ESC will call them. If you haven't these handlers, the default will be used which will be in both cases an EndDialog () call.
GeneralThank you !!memberFastfootskater12 Aug '07 - 20:52 
Sometimes things are so easy that you can not belive it Big Grin | :-D
 
Greetings from
the lake of constance (Germany)
 
jürgen
GeneralThanks NishmemberPaul Hooper12 Jul '06 - 1:52 
Thanks Nish!!
 
Even though others have indicated that the "bug" might not have been worthwhile reporting, your great article provided me with the clue I needed to make something work.
 
I wanted to have an on-screen keyboard that could send keystrokes to a modal dialog box but was stymied because the on-screen keyboard never got focus. Your revelation that modal dialog boxes were not modal made life much easier - one ::EnableWindow in the dialog box's OnInitDialog and everything works perfectly! I am sure that I would have eventually got things to work but your information saved me HOURS of time.
 
Thanks again for the information. Your article reinforces the point that sharing "odd" discoveries can make lots of people's lives much easier and not necessarily in the way you intended.
 
Big Grin | :-D Big Grin | :-D Big Grin | :-D Big Grin | :-D Big Grin | :-D Big Grin | :-D
 
Paul Hooper
 
If you spend your whole life looking over your shoulder, they will get you from the front instead.
GeneralC++ version suffers similar issuememberThrashMaster13 Apr '06 - 10:56 
Use of the bEnableParent flags results in a similar issue with sibling modal dialogs:
 
1. Parent window A is created.
 
2. Modal dialog B is created with A as parent. Since A is enabled, bEnableParent is set to true, and A is disabled.
 
3. Modal dialog C is created with A as parent (thus a sibling of B). Since A is disabled, bEnableParent remains false.
 
4. Modal dialog B is dismissed. Since bEnableParent for B is true, parent window A is enabled, even though modal dialog C is still present.
GeneralProblem with modal dialog stackmemberhickory3 Feb '06 - 4:59 
Hi there,
 
I have a problem with MFC modal dialogs which is a bit different than the one described here. Aynway, I was searching the internet and stumbled over this nice article which at least explains that the MFC CDialog has been developed just by humans Wink | ;-)
 
Here my problem: I have only one main window which pops up a modal dialog. On that dialog you can start a long term operation which itself opens another modal dialog (without closing the first one) showing some progress. The operation is done in a separate thread. If the thread has finished I send a WM_COMMAND IDOK message to the top most dialog which closes the dilaog. The rist dialog is closed right after DoModal is back and everything is fine.
 
But (I hate that but) under some ciscumstances (one of 10 or 20) I get an assertion failure in CWnd::RunModalLoop() in wincoe.cpp:4563 which is
 
// phase2: pump messages while available
do
{
--> ASSERT(ContinueModal());
 
for soem reasons the loop is entered and ContinueModal returns false. I only can assume a timing problem here, meaning that between checking ContinueModal() in the loop and entering the loop the internal flags must somehow change...
 
Does anyone can help me out? Confused | :confused:
 
Thanks Jan
GeneralRe: Problem with modal dialog stackmemberhickory16 Feb '06 - 1:12 
Maybe I should add that the first modal dialog is a suclassof CPropertySheet.
I remember that the problems started when I introduced them in my application.
 
Jan
GeneralRe: Problem with modal dialog stackmemberhickory16 Feb '06 - 1:18 
Me again... (thinking aloud)
 
I popup the modal progress dialog inside of the CProeprtySheet::PerformFinish method
and return TRUE such that the property sheet (which is in wizard mode) is closed afterwards.
 
I can feel that's the crux of the matter Confused | :confused:
 
Jan
GeneralRe: Problem with modal dialog stackmemberhickory16 Feb '06 - 8:59 
Okay, it's not CPropertySheet::PerformFinish. It's a function in my last page which is called by the "Wizard" but anyway, the facts are the same: if I return TRUE (which I do) the wizard is closed.
 
I pass the CPropertySheet as parent to the modal progress dialog. Is this a "dont't do"? Shall I use the parent of the CPropertySheet (the main window) also as parent for the "child" modal dialog?
AnswerRe: Problem with modal dialog stackmemberabc13a18 Sep '07 - 21:27 
I know it's quite late, but I have found your question when I was looking for a solution for a similar problem in my application. A background thread was terminating a modal dialog by sending IDOK command and another modal dialog box with the resoults was displayed by the main application thread right afterwards. And by displaying the 2nd dialog box I got the same problem as you did (failed assertion in ASSERT(ContinueModal()) in one of cca 3-4 tries).
After several hours of trying I used PostMessage instead of SendMessage for sending IDOK command in from the background thread and I am not getting the assertion message anymore (10 tries after another without error). I don't understand why it is, both calls should be thread-safe, but it seems to work.
I don't think it may help you, but someone else having the same problem now (someone like me) could appreciate it and avoid few hours of trying and swearing Wink | ;-)
 
Have a nice day
 
dizzy
GeneralMessage loopsmemberStephen Hewitt11 Jan '06 - 12:36 
Helpful article. One minor point: At the start when you're describing the difference between modal and modeless dialogs from the programmers perspective I think the fact that modal dialogs run their own message pump should be highlighted.
 
Steve

QuestionHow to enable parent AND one childmemberSven Appenrodt23 May '05 - 23:34 
I want to open a child-window (about-box) but let parent enabled.
I'm not sure but it seems to work...
 
// initializer
m_AboutOpening = FALSE
 
// when opening the about-box
SetTimer(2000,100,NULL);
SetTimer(2001,200,NULL);
 
// when the timer elapsed
void CParentDlg::OnTimer(UINT nIDEvent)
{
      KillTimer(nIDEvent);
      if (!m_AboutOpening)
      {
            AboutOpening = TRUE;
            CAboutDlg dlg(this);
            dlg.DoModal();
      }
      else
      {
            m_AboutOpening = FALSE;
            this->EnableWindow();
            CWnd::ContinueModal();
      }
      CDialog::OnTimer(nIDEvent);
}
 
But: You have to save the instance-ptr of the child-dlg, because when you close the main-dlg, the child will stay opened!!!
 
Do i have made some mistakes? :->
GeneralVC6 also needs UpdateData() in OnOK()memberbruce2g1 May '05 - 21:26 
I ran into the same problem, and i tried the solution, using vc6, but my member variables did not get updated.
 
I put a breakpoint on DoDataExchange(), and it took on entry to the dialog, but it did not get invoked after EndModalLoop(IDOK);
 
So then I tried a call to UpdateData() in my ONOK() handler -- yep, that seems to do it!
 
So you should add a call to UpdateData() in the OnOK() handler.
 
Bruce
GeneralMultiple Modal DialogsmemberDinplor18 Apr '05 - 8:12 
Visual studio allows you quite easily to create a "Multiple top-level documents" application.
This kind of application allows the user to have multiple frames - each can have its own multiple documents and views.
When having two frames opened, you can open from each one of them a modal dialog, using DoModal.
 
The problem is that once the latter dialog box is opened, the first dialog's DoModal method will NEVER exit until the latter one closes.
 
The reason for that is that as long as there's one dialog box ('A'), it is busy with its own RunModalLoop method. But once the user invokes the other modal dialog ('B'), RunModalLoop of A will "halt" (on DispatchMessage) until B finishes all its processing and actually bails out from its own DoModal.
 
Does anybody have any idea how to overcome this issue?
 
Thanks,
Ronen.
GeneralNon-modality of modal dialogsmemberYadnesh24 Nov '03 - 2:04 
Hi All,
 
I have some questions regarding modality of modal dialogs and CWinThread.   I am facing the below mentioned problems when displaying dialog based GUI from COM EXE.  
 
First about threads.   CWinThread had m_pMainWnd and m_pActiveWnd as public members.   I have GUI thread in COM EXE, in which m_pMainWnd points to a modeless dialog (created on the same thread).   The dialog does not have any controls and we have used it only for message queueing.  
What is the precise use of these members? What happens if I make them point to different windows during the thread's lifetime?     
 
Now, One of my interface methods posts a message to the modeless dialog, so that the GUI thread is responsible for furthur action and main thread of COM EXE remains free.   The message handler pops-up a modal dialog.   The controls in this dialog pop-up modal dialog...and so on forming a 'hierarchy of modal dialogs'.  
 
Problem:   I can easily click on dialog and use it!!!   Ideally only the top-most dialog chould be accisible.   Please suggest a solution.
 
Actually I have landed-up on a solution but I don't know how and why this works.
Solution:   Before launching the 'hierarchy of modal dialogs' set the m_pMainWnd to point to the main dialog of the client application.   After closing all the dialogs reset the m_pMainWnd to original value.   STRANGELY switching between the modal dialogs is not possible now.
 
Please help me in this regard.   I have searched many sites and checked the MSDN documentation but in vain.  
 
Regards,
Yadnesh Phadke

 
Yadnesh Phadke
Software Engineer,
Pune, India  
QuestionQuestion "DoModal" ?memberPetrisor20 Nov '03 - 5:54 
hello
i have a problem and i can't fix it
 
when i create a dialod with DoModal
i can't update form de place where
i call (of corse before the call of domodal)
domodal, the combobox (i have assigned
a variable to the combobox)
but i can update a list and only a list
 
eg:
 
CDoModal dlg;
 
dlg.m_combobox.InsertIem("Hurray");
//here is where the programs fail
 

//I'm not sure that the InsertItem
//is the function that inserts
//an item
dlg.DoModal();
 
if i display the box with create is
ok and work properly
 
please help me
 
Sex helps programmers
AnswerRe: Question "DoModal" ?memberDavidCrow25 Feb '05 - 6:15 
Petrisor wrote:
dlg.m_combobox.InsertIem("Hurray");
 
You cannot do this here as the combobox control does not yet exist. Populate controls in the dialog's OnInitDialog() method.
 

"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow


QuestionWhat about scenario with one modal dialog and two frame windows?memberdomKing25 Oct '03 - 4:50 
This article addresses the "unusual scenarios where there might be two modal dialogs both having the same parent." What about the scenario where you wish to enforce modality for a dialog which arrises while two (or more) different frame windows are open? The modal dialog handling in MFC seems to assume you only have one frame window. It does not properly enforce modality for the other frame window(s) in this situation.
 
I have tried various approaches with changing the ownership of the main window and/or other frame windows, which has improved the situation. However, it has not solved all problems. For example, it is still possible to click on the taskbar to (semi-)activate the main window and/or other frame windows. Here is the exact situation:
 
1. Main window opens when app starts.
2. Some (user) action causes another frame window to open. Now two frame windows are open.
3. Some (user) action causes second frame window, which is not the main window, to open a modal dialog (using DoModal).
4. User clicks on task bar to activate main window. (All other means of activating main window have been successfully disabled, like Alt+Tab and clicking on it.)
5. Window semi-activates, meaning that it receives WM_ACTIVATE but does not visually appear to really be active. Additionally, modal dialog visually appears to have been de-activated.
6. User presses accelerator key combination to trigger another modal dialog causing application to totally hang. It is no longer possible to activate or interact with the modal dialog that is open or any of its frame windows.
 
I have searched high and low for a solution to this problem, but this article comes the closest. Any ideas on how to solve this one?
GeneralThe correct way ismemberJimmyO17 Apr '03 - 3:47 
void CChildDialog::EndDialog(int nResult)
{
ASSERT(::IsWindow(m_hWnd));
 
if (m_nFlags & (WF_MODALLOOP|WF_CONTINUEMODAL))
EndModalLoop(nResult);
DestroyWindow();
}
Big Grin | :-D
GeneralRe: The correct way is [Actually no!]editorNishant S17 Apr '03 - 5:47 
Hey Jimmy
 
This is not correct. Do NOT call DestroyWindow, there is still some processing that MFC has to do. They'll call DestroyWindow later on their own.
 
Regards,
Nish
 

Author of the romantic comedy

Summer Love and Some more Cricket [New Win]

Review by Shog9
Click here for review[NW]

Questiony cant we access some of the parent's member variables?memberMiguel Lopes14 Apr '03 - 2:44 
Hi.
 
I have a problem. I create a modal dialog and i cant access some of the dialog's parent wnd. 1st i get a valid pointer to the parent, and i can access all functions and variables EXCEPT...
CTypedPtrArray arrays!! I have some dynamic CObjects arrays and all works fine till i try to get a valid pointer (from inside the dialog) to an Object inside the array and i cant!! Help!!!!!

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 7 Apr 2003
Article Copyright 2003 by Nish Sivakumar
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid