test: mndstry.c Source File

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# mndstry.c

Go to the documentation of this file.

    00001 /**************************** Module Header ********************************\
    00002 * Module Name: mndstry.c
    00003 *
    00004 * Copyright (c) 1985 - 1999, Microsoft Corporation
    00005 *
    00006 * Menu Destruction Routines
    00007 *
    00008 * History:
    00009 * 10-10-90 JimA       Created.
    00010 * 02-11-91 JimA       Added access checks.
    00011 * 03-18-91 IanJa      Window revalidation added (none required)
    00012 \***************************************************************************/
    00013
    00014 #include "precomp.h"
    00015 #pragma hdrstop
    00016
    00017 /***************************************************************************\
    00018 * DestroyMenu
    00019 *
    00020 * Destroy a menu and free its memory.
    00021 *
    00022 * History:
    00023 * 10-11-90 JimA         Translated from ASM.
    00024 * 02-11-91 JimA         Added access checks.
    00025 \***************************************************************************/
    00026
    00027 BOOL _DestroyMenu(
    00028     PMENU pMenu)
    00029 {
    00030     PITEM pItem;
    00031     int i;
    00032     PDESKTOP rpdeskLock;
    00033
    00034     if (pMenu == NULL)
    00035         return FALSE;
    00036
    00037     /*
    00038      * If the object is locked, just mark it for destroy and don't
    00039      * free it yet.
    00040      */
    00041     if (!HMMarkObjectDestroy(pMenu))
    00042         return TRUE;
    00043
    00044     /*
    00045      * Go down the item list and free the items
    00046      */
    00047     pItem = pMenu->rgItems;
    00048     for (i = pMenu->cItems; i--; ++pItem)
    00049         MNFreeItem(pMenu, pItem, TRUE);
    00050
    00051     /*
    00052      * free the menu items
    00053      */
    00054     if (pMenu->rgItems)
    00055         DesktopFree(pMenu->head.rpdesk, pMenu->rgItems);
    00056
    00057     /*
    00058      * Because menus are the only objects on the desktop owned
    00059      * by the process and process cleanup is done after thread
    00060      * cleanup, this may be the last reference to the desktop.
    00061      * We must lock the desktop before unlocking
    00062      * the parent desktop reference and freeing the menu to
    00063      * ensure that the desktop will not be freed until after
    00064      * the menu is freed.  Don't use static locks because
    00065      * the pti for this thread will not be valid during
    00066      * process cleanup.
    00067      */
    00068     rpdeskLock = NULL;
    00069     LockDesktop(&rpdeskLock, pMenu->head.rpdesk, LDL_FN_DESTROYMENU, (ULONG_PTR)PtiCurrent());
    00070
    00071     /*
    00072      * Unlock all menu objects.
    00073      */
    00074     Unlock(&pMenu->spwndNotify);
    00075
    00076     HMFreeObject(pMenu);
    00077
    00078     UnlockDesktop(&rpdeskLock, LDU_FN_DESTROYMENU, (ULONG_PTR)PtiCurrent());
    00079
    00080     return TRUE;
    00081 }