0
votes

I'm trying to nest dialog boxes and it works effortlessly with a single level of nesting but the second level "breaks" - the inner-most dialog doesn't get events.

[IDD_NESTEDDLG_DIALOG]
   |
   +--- [IDD_CHILD1]
            |
            +--- [IDD_CHILD2]

Both children dialog boxes are set to have style as "Child". For this test I'm just using a straight-up MFC wizard: created a dialog-based app, added two children dialog boxes (both derived from CDialogEx), added member-variables to hold instances of those children dialog boxes. No customization beyond creating children dialog boxes and displaying them in OnInitDialog():

BOOL CnestedDlgDlg::OnInitDialog()
{
    // ... MFC-generated bootstrap

    m_child1.Create(IDD_CHILD1);
    m_child1.ShowWindow(SW_SHOW);

    return TRUE;
}

and

BOOL CChild1::OnInitDialog()
{
    // ... MFC-generated bootstrap

    m_child2.Create(IDD_CHILD2);
    m_child2.ShowWindow(SW_SHOW);

    return TRUE;
}

When I run this code both nested dialog boxes are properly shown yet only the top-level and first-level dialog boxes get events. Clicking on IDD_CHILD1's "OK" or "Cancel" button promptly closes that intermediate dialog and only then the inner-most child dialog starts getting events.

I feel like there's something very trivial I'm missing here but hours of playing with various settings ("Control", "Control Parent", "No Idle Message", "No Parent Notify") and searching the Web yielded no progress so far.

How do I properly nest dialog boxes so that the second-level child's controls get events while the top-level and first-level dialog controls are also active?

UPDATE
Once I made both children boxes have "normal" borders I was able to move them around inside the top-level dialog box and noticed that the second-level child feels more like a sibling to the first-level dialog box than its child. The issue is probably there, but I still don't know how to properly deal with that. And there's also a problem with a re-draw as it seems both children boxes don't get to be repainted unless the app is minimized/restored or moved out the screen.

1
Show the code that actually invokes your nested dialogues. If you want nested dialogues and yet want to interact with the parent dialogue then they have to both be modeless dialogues. You can't have two model popups at the same time because the first will block all messages.Andrew Truckle
They are not popups, they are children dialog boxes (placed inside each other, like matreshka dolls). "The code that actually invokes" is listed already - nothing beyond a call to Create() and ShowWindow()YePhIcK
Control and Child must be set for child dialogs embedded inside a dialog.xMRi
Just tried (set both Control and Child on both children dialog boxes) - same negative result.YePhIcK

1 Answers

1
votes

From what I can gather from your post, you are creating both dialogs as children of the main dialog and dialogs are position one on the top of another. Besides setting WS_CHILD and DS_CONTROL, you will have to pass a pointer to the parent. So, first dialog is a child of the main and the second is a child of the first nested. Probably WS_CLIPCHILDREN to eliminate repainting problem you mentioned but this is irrelevant since you will not move dialogs around. I wrote a sample you can download HERE

It has mouse and buttons handlers for showing messages you are receiving