Microsoft KB Archive/125435

= PRB: Hidden MDI Child Window Causes Corrupted MDI Window Menu =

Article ID: 125435

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 1.0 Professional Edition

 Microsoft Visual C++ 1.5 Professional Edition

 Microsoft Visual C++ 5.0 Learning Edition

 Microsoft Visual C++ 5.0 Learning Edition</li></ul>

 Microsoft Visual C++ 4.2 Enterprise Edition</li></ul>

 Microsoft Visual C++ 2.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.1</li></ul>

 Microsoft Visual C++ 6.01 Professional Edition</li></ul>

 Microsoft Visual C++ 4.0 Professional Edition</li></ul>

 Microsoft Visual C++ 4.1 Subscription</li></ul>

 Microsoft Visual C++ 4.2 Professional Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q125435

<div class="symptoms_section">

SYMPTOMS
If an MDI child window is hidden or disabled, the Window menu is not properly updated for the visible MDI child windows. Specifically, the Window menu continues to show deleted MDI child windows or fails to add new MDI child windows to the list.

<div class="cause_section">

CAUSE
These problems occur only after at least one MDI child window has been destroyed. When Windows destroys an MDI child window, it moves activation to a different window. This activation change causes MFC to change and refresh the MDI frame window's menu. Windows does not handle this menu refresh message correctly while in the process of destroying an MDI child window when other windows are hidden or disabled. This problem does not occur if the window being destroyed is hidden or disabled.

<div class="resolution_section">

RESOLUTION
To work around this problem, program your application to ensure that that an MDI child window is always hidden or disabled before it is destroyed. The destruction of MDI child windows is managed by the MDICLIENT window in the processing of the WM_MDIDESTROY message. You can customize the behavior of this message as follows:

<ol> Subclass the MDICLIENT window and provide a handler for the message. For an example that shows how to subclass the MDICLIENT window, please see the following article in the Microsoft Knowledge Base:

129471 How to SubClass the MDIClient by Using MFC

</li> Add a message handler for the WM_MDIDESTROY message to the class used to subclass the MDICLIENT window; this example calls it the CMDIClientWnd class. This message is not listed by ClassWizard, so you will need to add the handler manually. For additional information about how to do this, please see the following article in the Microsoft Knowledge Base:

99848 Use ON_MESSAGE Macro to Map Less-Common Messages

</li> <li> Implement the OnMDIDestroy function as follows: LRESULT CMDIClientWnd::OnMDIDestroy(WPARAM wParam,LPARAM lParam) {

// wParam contains the hwnd of the child being destroyed HWND hwndChild = (HWND) wParam; ::ShowWindow(hwndChild,SW_HIDE); return Default; };                       </li></ol>

NOTE: It has been reported that in some cases, a call to ::EnableWindow(hwndChild,FALSE); is required before the call to ::ShowWindow.

Keywords: kbmenu kbmdi kbprb KB125435

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.