Modifying the System Menu of an MDI Child Window

Last reviewed: August 12, 1997
Article ID: Q77930

The information in this article applies to:

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

SUMMARY

The system menu of an MDI child can be modified only after the WM_CREATE message for the MDI child is processed. If an application tries to modify the system menu of an MDI child during the processing of the child's WM_CREATE message, the system menu will not be changed.

MORE INFORMATION

It is common to try to alter a window's system menu during the processing of its WM_CREATE message. This method has no effect on the system menu of an MDI child, however, because of the way a MDI child window is created:

  1. The MDI client window calls the CreateWindowEx() function to create the window.

  2. Then, the MDI client window replaces the default system menu with the special MDI child system menu.

The WM_CREATE message is sent to the child window by CreateWindowEx(). Changes to the MDI child's system menu on WM_CREATE have no effect because the MDI client assigns a special MDI system menu to the child after CreateWindowEx() returns.

To work around this design decision, the child window procedure can post a custom message to itself during the processing of its WM_CREATE message. This custom message is processed after the MDI client has finished creating the MDI child. The code for this workaround might resemble the following:

#define WM_ADDMENUITEM (WM_USER+1)

LONG FAR PASCAL MDIChildWndProc(HWND hWnd,
                                WORD wMsg,
                                WORD wParam,
                                LONG lParam)
{
    switch (wMsg)
       {
    case WM_CREATE:
       PostMessage(hWnd, WM_ADDMENUITEM, 0, 0L);
       break;

    case WM_ADDMENUITEM:
       {
       HMENU        hMenu;

       hMenu = GetSystemMenu(hWnd, FALSE);
       InsertMenu(hMenu, -1, MF_BYPOSITION, IDM_NEW,
             (LPSTR)"New Item\0");
       DrawMenuBar(hWnd);
       }
       break;

    default:
       return DefMDIChildProc(hWnd, wMsg, wParam, lParam);
       }

    return 0;
}

Keywords          : kb16bitonly UsrMdi kbhowto
Version           : 3.0 3.1
Platform          : WINDOWS
Issue type        : kbhowto


================================================================================


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: August 12, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.