Ejemplo n.º 1
0
 public static extern bool SetMenuInfo(IntPtr hmenu,
                                       ref MENUINFO lpcmi);
Ejemplo n.º 2
0
    void RemoveShellMenuItems(Menu menu) {
      const int tag = 0xAB;
      var remove = new List<int>();
      int count = User32.GetMenuItemCount(menu.Handle);
      var menuInfo = new MENUINFO();
      var itemInfo = new MENUITEMINFO();

      menuInfo.cbSize = Marshal.SizeOf(menuInfo);
      menuInfo.fMask = MIM.MIM_MENUDATA;
      itemInfo.cbSize = (uint)Marshal.SizeOf(itemInfo);
      itemInfo.fMask = MIIM.MIIM_ID | MIIM.MIIM_SUBMENU;

      // First, tag the managed menu items with an arbitary 
      // value (0xAB).
      TagManagedMenuItems(menu, tag);

      for (int n = 0; n < count; ++n) {
        User32.GetMenuItemInfo(menu.Handle, n, true, ref itemInfo);

        if (itemInfo.hSubMenu == IntPtr.Zero) {
          // If the item has no submenu we can't get the tag, so 
          // check its ID to determine if it was added by the shell.
          if (itemInfo.wID >= m_CmdFirst) remove.Add(n);
        } else {
          User32.GetMenuInfo(itemInfo.hSubMenu, ref menuInfo);
          if (menuInfo.dwMenuData != tag) remove.Add(n);
        }
      }

      // Remove the unmanaged menu items.
      remove.Reverse();
      foreach (int position in remove) {
        User32.DeleteMenu(menu.Handle, position, MF.MF_BYPOSITION);
      }
    }
Ejemplo n.º 3
0
		public static extern bool SetMenuInfo(IntPtr hmenu, ref MENUINFO lpcmi);
Ejemplo n.º 4
0
    void TagManagedMenuItems(Menu menu, int tag) {
      var info = new MENUINFO();
      info.cbSize = Marshal.SizeOf(info);
      info.fMask = MIM.MIM_MENUDATA;
      info.dwMenuData = tag;

      foreach (MenuItem item in menu.MenuItems) {
        User32.SetMenuInfo(item.Handle, ref info);
      }
    }