OnClosing and DocumentWindows bug

Docking/MDI for Windows Forms Forum

Posted 17 years ago by Ernst
Avatar
If I cancel main form OnClosing event in "Standard" MDI mode all MDI document windows will close. If DockManager is in "Tabbed" mode then Document Windows stay open as expected.

Thanks,
Ernst

[Modified at 02/05/2007 02:25 PM]

[Modified at 02/05/2007 02:25 PM]

Comments (5)

Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hmm... I did some debugging and found that it is the .NET Framework (and probably core Windows behavior) that is actually closing all the MDI child forms before the OnClosing method is called on the parent Form. It is not our code that is closing them.

So unfortunately in this situation I'm not sure what we can do since it appears to be how .NET operates.

You should be able to repro this with a regular MDI Form and an MDI child Form. In both, override OnClosing and see the order in which they execute.

Of course we're open to any ideas you have.


Actipro Software Support

Posted 17 years ago by Ernst
Avatar
I resolved this by switching from DocumentWindows to ToolWindows. The later can be used as MDI documents so this is perfect for me. After I made the switch I'm not sure why anyone would use DocumentWindows. It seems that ToolWindows support all possible scenarios.

Question: when I close tool window it actually stays in ToolWindows collection of the dock manager. Is this by design? This seems to be right as if I need to create tool window with the same key I can first search for existing inactive tool window and reuse it if found (thus showing it in the same size/position as the last time). I just want to make sure this is done intentionally and it will not be fixed later as a bus (since I'm relying on that behavior in my code).

Thanks,
Ernst
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Tool windows have different lifetimes than document windows. Tool windows are meant to be displayed, hidden and reused. It is up to the developer to dispose of them. Documents on the other hand are only supposed to be opened and when they are closed, they automatically dispose (although there is an option to turn that off). Tool windows are saved in layout files, while document windows are not. Tool windows can be docked anywhere, while document windows can only live in the MDI area.

I hope that explains the differences pretty well.


Actipro Software Support

Posted 17 years ago by Ernst
Avatar
> Of course we're open to any ideas you have.
Here is how I fixed that issue with Microsoft closing MDI windows too early:

protected override void WndProc(ref Message m) 
{
    const int WM_CLOSE = 16;

    if (m.Msg == WM_CLOSE)
    {
        // Implement method CanClose which should return true if 
                                   // all MDI windows can close
        if (CanClose ())           // You can't do this in OnClosing 
            base.WndProc(ref m);   // because .NET framework closes all
                                   // MDI windows before you have a chance
                                   // to cancel Close event.
    }
    else
    {                             
        base.WndProc(ref m);
    }
}
Posted 17 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Good information for everyone, Ernst. Thanks!


Actipro Software Support

The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.