An application can change a window's parent window by using the WinSetParent function. For example, in an application that uses child windows to display documents, you might want only the active document window to show a system menu. You can do this by changing that menu's parent window back and forth between the document window and the object window when WM_ACTIVATE messages are received. This technique is shown in the code fragment in the following figure.

    switch (msg) {

    case WM_ACTIVATE:  {

    HWND hwndFrame, hwndSysMenu, hwnd;

        /* Get the handles of the frame window and system menu.        */
        hwndFrame = WinQueryWindow(hwnd, QW_PARENT);
        hwndSysMenu = WinWindowFromID(hwndFrame, FID_SYSMENU);

        /* If the window is being activated, make the frame window the */
        /* parent of the system menu. Otherwise, hide the system menu  */
        /* by making the object window the parent.                     */

        if ( SHORT1FROMMP(mp1))
            WinSetParent(hwndSysMenu, hwndFrame, TRUE);

        else
            WinSetParent(hwndSysMenu, HWND_OBJECT, TRUE);

        }

        return 0;
    }


[Back] [Next]