PRB: Processing the WM_QUERYOPEN Message in an MDI Application

ID: Q99411


The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK)
  • Microsoft Windows Software Development Kit (SDK) 3.1
  • Microsoft Windows 2000


SYMPTOMS

When a multiple document interface (MDI) child window processes the WM_QUERYOPEN message to prevent the child from being restored out of a minimized state, the system menu and restore button are not removed from the menu bar when a maximized MDI child loses the focus or is closed.

This problem occurs only when the maximized MDI child loses the focus or is closed and the focus is given to an MDI child that returns 0 (zero) on the WM_QUERYOPEN message.


CAUSE

When an MDI child is maximized, the system menu and restore button are added to the frame menu as bitmap menu items. When a maximized MDI child is destroyed or another MDI child is given the focus, the MDI child given the focus afterwards is maximized to replace the old MDI child. Windows cannot maximize an MDI child when it is processing the WM_QUERYOPEN message, and therefore the child is not maximized. Unfortunately, the system menu and restore button bitmaps are not removed from the menu bar.


RESOLUTION

To prevent this problem, restore the maximized MDI child before giving the focus to another child.


MORE INFORMATION

It may sometimes be desirable to prevent an MDI child from being restored during part or all of its life. This can be done by trapping the WM_QUERYOPEN message by placing the following code in the window procedure of the MDI child:


   case WM_QUERYOPEN:
      return 0; 
Unfortunately, this causes the added restore and system menu bitmaps to remain on the menu bar when a maximized MDI child loses the focus or is closed and the focus is given to a child processing this message. The following code can be used to restore a maximized MDI child when it loses the focus:

     case WM_MDIACTIVATE:
        if ((wParam == FALSE) && (IsZoomed(hwnd)))
           SendMessage(hwndMDIClient, WM_MDIRESTORE, hwnd, 0L);

        return DefMDIChildProc (hwnd, msg, wParam, lParam); 

Additional query words:

Keywords : kbcode kbMDI kbNTOS kbWinOS2000 kbSDKWin32 kbGrpUser kbWinOS kbWndw
Version : WINDOWS:3.1
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: January 25, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.