CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Guest

    Conflicting Modal Dialogs

    I have two modal dialog problems which may or may not be related:
    Case 1: I have a dialog with an Apply button so that settings changes happen on the main window without dismissing the dialog. However, during the update of the main window it is possible for a modal dialog to be created. When this second dialog is dismissed, the first is no longer modal.

    Case 2: I have a worker thread which can cause a modal dialog to be displayed. It does this by posting a message to the main window, and waiting for the main thread to signal the worker thread to continue. In the meantime the main thread displays the modal dialog. However, as for case 1, there may already be a modal dialog on screen when the dialog is displayed on behalf of the worker thread, and the same problems arise.

    Any simple code (preferred) or strategies for workarounds would be appreciated.

    Derek


  2. #2
    Guest

    Re: Conflicting Modal Dialogs

    In case its of use to someone else, the following override of DoModal appears
    to do the trick.

    int CMyDialog:oModal()
    {
    //Find the current active window (which may be another modal dialog)
    //and disable it
    HWND hActiveWindow = ::GetActiveWindow();
    ::EnableWindow(hActiveWindow, FALSE);

    //Call the base class
    int status = CDialog:oModal();

    //disable the main window to undo the actions of CDialog:oModal
    //which enables the main window in PostModal
    CWnd* pWnd = AfxGetMainWnd();
    pWnd->EnableWindow(FALSE);

    //re-enable the previously active window (which may be a modal dialog
    //or the main window (or something else ?)
    //if main window was active, then we'll just be re-enabling it here
    ::EnableWindow(hActiveWindow, TRUE);
    ::SetActiveWindow(hActiveWindow);
    ::SetFocus(hActiveWindow);

    return status;
    }

    Derek.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured