Source code of Windows XP (NT5)
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.

145 lines
3.0 KiB

  1. // File: menuutil.cpp
  2. #include "precomp.h"
  3. #include "resource.h"
  4. #include "MenuUtil.h"
  5. #include "cmd.h"
  6. #include "ConfUtil.h"
  7. /****************************************************************************
  8. *
  9. * FUNCTION: FillInTools()
  10. *
  11. * PURPOSE: Fills in the Tools menu from a specified reg key
  12. *
  13. ****************************************************************************/
  14. UINT FillInTools( HMENU hMenu,
  15. UINT uIDOffset,
  16. LPCTSTR pcszRegKey,
  17. CSimpleArray<TOOLSMENUSTRUCT*>& rToolsList)
  18. {
  19. ASSERT(pcszRegKey);
  20. RegEntry reToolsKey(pcszRegKey, HKEY_LOCAL_MACHINE);
  21. if (ERROR_SUCCESS == reToolsKey.GetError())
  22. {
  23. BOOL fFirstItem = TRUE;
  24. RegEnumValues rev(&reToolsKey);
  25. while (ERROR_SUCCESS == rev.Next())
  26. {
  27. TOOLSMENUSTRUCT* ptms = new TOOLSMENUSTRUCT;
  28. if (NULL != ptms)
  29. {
  30. ptms->mods.iImage = 0;
  31. ptms->mods.hIcon = NULL;
  32. ptms->mods.hIconSel = NULL;
  33. ptms->mods.fChecked = FALSE;
  34. ptms->mods.fCanCheck = FALSE;
  35. ptms->mods.pszText = (LPTSTR) &(ptms->szDisplayName);
  36. ptms->uID = ID_EXTENDED_TOOLS_ITEM + uIDOffset;
  37. if ((REG_SZ == rev.GetType()) && (0 != rev.GetDataLength()))
  38. {
  39. lstrcpyn( ptms->szExeName,
  40. (LPTSTR) rev.GetData(),
  41. ARRAY_ELEMENTS(ptms->szExeName));
  42. SHFILEINFO shfi;
  43. if (NULL != SHGetFileInfo(
  44. ptms->szExeName,
  45. 0,
  46. &shfi,
  47. sizeof(shfi),
  48. SHGFI_ICON | SHGFI_SMALLICON))
  49. {
  50. ptms->mods.hIcon = shfi.hIcon;
  51. }
  52. }
  53. else
  54. {
  55. ptms->szExeName[0] = _T('\0');
  56. }
  57. if (NULL == ptms->mods.hIcon)
  58. {
  59. // The icon wasn't filled in, so use a default icon
  60. ptms->mods.hIcon = ::LoadIcon(NULL, IDI_APPLICATION);
  61. }
  62. lstrcpyn( ptms->szDisplayName,
  63. rev.GetName(),
  64. ARRAY_ELEMENTS(ptms->szDisplayName));
  65. rToolsList.Add(ptms);
  66. if (fFirstItem)
  67. {
  68. // add a separator first
  69. ::AppendMenu( hMenu,
  70. MF_SEPARATOR,
  71. ID_EXTENDED_TOOLS_SEP,
  72. NULL);
  73. fFirstItem = FALSE;
  74. }
  75. if (::AppendMenu( hMenu,
  76. MF_ENABLED | MF_OWNERDRAW,
  77. ptms->uID,
  78. (LPCTSTR) ptms))
  79. {
  80. uIDOffset++;
  81. }
  82. }
  83. }
  84. }
  85. return uIDOffset;
  86. }
  87. /****************************************************************************
  88. *
  89. * FUNCTION: CleanTools()
  90. *
  91. * PURPOSE: Cleans up a tools menu
  92. *
  93. ****************************************************************************/
  94. UINT CleanTools(HMENU hMenu,
  95. CSimpleArray<TOOLSMENUSTRUCT*>& rToolsList)
  96. {
  97. DebugEntry(CleanTools);
  98. if (NULL != hMenu)
  99. {
  100. // remove separator
  101. ::RemoveMenu(hMenu, ID_EXTENDED_TOOLS_SEP, MF_BYCOMMAND);
  102. }
  103. while (0 != rToolsList.GetSize())
  104. {
  105. TOOLSMENUSTRUCT* ptms = rToolsList[0];
  106. if (NULL != ptms)
  107. {
  108. if (NULL != ptms->mods.hIcon)
  109. {
  110. ::DestroyIcon(ptms->mods.hIcon);
  111. }
  112. if (NULL != ptms->mods.hIconSel)
  113. {
  114. ::DestroyIcon(ptms->mods.hIconSel);
  115. }
  116. if (NULL != hMenu)
  117. {
  118. ::RemoveMenu(hMenu, ptms->uID, MF_BYCOMMAND);
  119. }
  120. delete ptms;
  121. rToolsList.RemoveAt(0);
  122. }
  123. }
  124. DebugExitULONG(CleanTools, 0);
  125. return 0;
  126. }