Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.2 KiB

  1. /**************************** Module Header ********************************\
  2. * Module Name: mndstry.c
  3. *
  4. * Copyright (c) 1985 - 1999, Microsoft Corporation
  5. *
  6. * Menu Destruction Routines
  7. *
  8. * History:
  9. * 10-10-90 JimA Created.
  10. * 02-11-91 JimA Added access checks.
  11. * 03-18-91 IanJa Window revalidation added (none required)
  12. \***************************************************************************/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. /***************************************************************************\
  16. * DestroyMenu
  17. *
  18. * Destroy a menu and free its memory.
  19. *
  20. * History:
  21. * 10-11-90 JimA Translated from ASM.
  22. * 02-11-91 JimA Added access checks.
  23. \***************************************************************************/
  24. BOOL _DestroyMenu(
  25. PMENU pMenu)
  26. {
  27. PITEM pItem;
  28. int i;
  29. PDESKTOP rpdeskLock;
  30. if (pMenu == NULL)
  31. return FALSE;
  32. /*
  33. * If the object is locked, just mark it for destroy and don't
  34. * free it yet.
  35. */
  36. if (!HMMarkObjectDestroy(pMenu))
  37. return TRUE;
  38. /*
  39. * Go down the item list and free the items
  40. */
  41. pItem = pMenu->rgItems;
  42. for (i = pMenu->cItems; i--; ++pItem)
  43. MNFreeItem(pMenu, pItem, TRUE);
  44. /*
  45. * free the menu items
  46. */
  47. if (pMenu->rgItems)
  48. DesktopFree(pMenu->head.rpdesk, pMenu->rgItems);
  49. /*
  50. * Because menus are the only objects on the desktop owned
  51. * by the process and process cleanup is done after thread
  52. * cleanup, this may be the last reference to the desktop.
  53. * We must lock the desktop before unlocking
  54. * the parent desktop reference and freeing the menu to
  55. * ensure that the desktop will not be freed until after
  56. * the menu is freed. Don't use static locks because
  57. * the pti for this thread will not be valid during
  58. * process cleanup.
  59. */
  60. rpdeskLock = NULL;
  61. LockDesktop(&rpdeskLock, pMenu->head.rpdesk, LDL_FN_DESTROYMENU, (ULONG_PTR)PtiCurrent());
  62. /*
  63. * Unlock all menu objects.
  64. */
  65. Unlock(&pMenu->spwndNotify);
  66. HMFreeObject(pMenu);
  67. UnlockDesktop(&rpdeskLock, LDU_FN_DESTROYMENU, (ULONG_PTR)PtiCurrent());
  68. return TRUE;
  69. }