WMDIParent Close handler

There is a bug in WMDIParent in the Close handler, which performs (or should) a WQueryCloseEvent on all children.

The Win32 message handler for WM_MDINEXT returns 0 but the component code uses this as the next MDI child handle. So the loop executes only once for the active child.

The code *should* use WM_MDIGETACTIVE after this call to get the child handle and process all child windows. If you have more than one open child window that needs saving, only the first gets a WQueryCloseEvent. The following code fixes the bug in WMDIParent for the WQueryCloseEvent handling.

I chose not to fix the Destroy problem which also exists for the same reason because by following P++ methods for MDI programs it's not needed.

  1. In the MDIParent form's Create handler add:
    // This stops double QueryClose events
    RemoveEventHandler( WQueryCloseEvent, WEventHandlerCast(WMDIParent, DefaultEventHandler) );
    SetEventHandler( WQueryCloseEvent, this, WEventHandlerCast(Form1, Form1_QueryClose) );

    Form1 is the MDIParent class name. This removes the default handler and reinstalls the forms' handler.
  2. Add a QueryClose handler to the main form and add to it:
    WMDIChild *activeChild;
    WMDIChild *child;
    // Ask all of the children first if its OK to close
    activeChild = GetActiveChild( NULL );
    for( child = activeChild; child != 0 ; )
     if( child->CallEventHandler( WQueryCloseEvent, this ) )
     return TRUE;
     child = GetActiveChild( NULL );
     if( child == activeChild )
    return FALSE;

    This is essentially what the P++ component library was supposed to do for the QueryClose handler in the DefaultEventHandler. Submitted by: Bill Auerbach

The bug exists in Power 2.5, 2.1 and probably in all previous versions.

Submitted by Bill Auerbach