Terminating the Creation of an MDI Child Window

Last reviewed: July 23, 1997
Article ID: Q80125
3.00 3.10 WINDOWS kbprg

The information in this article applies to:

  • Microsoft Windows Software Development Kit (SDK) for Windows versions 3.0 and 3.1

In an application designed with the Microsoft Windows multiple document interface (MDI), there are situations in which it is desirable to destroy an MDI child window during the processing of its WM_CREATE message. For example, the design of the application may require terminating window creation if a memory allocation needed to hold data for an MDI child fails.

Unfortunately, returning -1 to end processing of the WM_CREATE message will not cleanly destroy the child window. Similarly, posting a WM_CLOSE message will cause the display to flash as the child is drawn, made active, and destroyed. This article describes a technique to avoid this unacceptable visual effect.

To avoid the flash, the application can clear the redraw flag for the MDI client window. This prevents the MDI client window and its children from painting. The remainder of this article contains code to implement this technique.

Before the application processes the MDI child window's WM_CREATE message, it does not change its display to reflect the new child window. If the application determines that it must abort creating the MDI child window at this time, it should clear the MDI client window's redraw flag and post a WM_CLOSE message to the child window. When the application processes the WM_DESTROY message, turn the redraw flag back on. The following code demonstrates these steps:

    case WM_CREATE:

        ...

        if (DestroyMePolitely)
            {
            SendMessage(hWndMDIClient, WM_SETREDRAW, FALSE, 0L);
            PostMessage(hWnd, WM_CLOSE, 0, 0L);
            }
        break;

    ...

    case WM_DESTROY:
        SendMessage(hWndMDIClient, WM_SETREDRAW, TRUE, 0L);


Additional reference words: 3.00 3.10
KBCategory: kbprg
KBSubcategory: UsrMdi
Keywords : kb16bitonly


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 23, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.