Accessing Parent Window's Menu from Child Window w/ focus

Last reviewed: November 2, 1995
Article ID: Q92527
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) versions 3.1
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.5 and 3.51
        - Microsoft Windows 95 version 4.0
    

SUMMARY

In an MDI-like application, the user must be allowed to pull down menus in the parent window by using menu mnemonics even though the child window or one of its children may have the focus. This can be done by creating child windows without a system menu or by processing the WM_MENUCHAR and WM_SYSCOMMAND/SC_KEYMENU messages to programatically pull down the parent's menu.

MORE INFORMATION

If a child window with a system menu has the focus and the user attempts to access the parent's menu with the keyboard using the menu mnemonic (ALT+mnemonic character), Windows will beep and the parent's menu will not be pulled down. This problem occurs because the parent window does not have the focus and because the window with the focus does not have a menu corresponding to the mnemonic. (Child windows cannot have menus other than the system menu.)

If the child window with the focus does not have a system menu, Windows assumes that the menu mnemonic is for the nearest ancestor with a system menu and passes the message to that parent. Consequently, it is possible to use menu mnemonics to pull down a parent's menu if the descendant windows do not have system menus.

If the child window with the focus has a system menu, Windows will beep if a menu mnemonic corresponding to a parent menu is typed. This can be prevented and the parent menu can be dropped down using the following code in the window procedure of the child window:

 case WM_MENUCHAR:
    PostMessage(hwndWindowWithMenu, WM_SYSCOMMAND, SC_KEYMENU, wParam);
    return(MAKELRESULT(0, 1));

WM_MENUCHAR is sent to the child window when the user presses a key sequence that does not match any of the predefined mnemonics in the current menu. wParam contains the mnemonic character. The child window posts a WM_SYSCOMMAND/SC_KEYMENU message to the parent whose menu is to be dropped down, with lParam set to the character that corresponds to the menu mnemonic.

The above code can also be used if the child window with the focus does not have a system menu but an intermediate child window with a system menu exists between the child with the focus and the ancestor whose menu is to be dropped. In this case, the code would be placed in the intermediate window's window procedure.


Additional reference words: 3.10 3.00 3.50 3.51 4.00 95
KBCategory: kbui
KBSubcategory: UsrMen


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: November 2, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.