Exemple #1
0
        /// <summary>
        /// Add an item at a certain index to the system menu.
        /// </summary>
        /// <param name="type">The type of the item.</param>
        /// <param name="index">The index the item should be added.</param>
        /// <param name="text">The text of the item.</param>
        /// <returns>The item itself.</returns>
        public SystemMenuItem InsertItem(SystemMenuItemType type, int index, string text = "")
        {
            List <int> usedIDs = GetUsedIDs();
            int        id      = 0;

            while (usedIDs.Contains(id))
            {
                id++;
            }
            SystemMenuItem item = new SystemMenuItem(this, Menu, id);

            SysMenuAPI.InsertMenu(Menu, index, SysMenuAPI.Flags.MF_BYPOSITION | (type == SystemMenuItemType.STRING ? SysMenuAPI.MenuTypes.MF_STRING : SysMenuAPI.MenuTypes.MF_SEPARATOR), id, text);
            Items.Insert(index, item);
            return(item);
        }
Exemple #2
0
        /// <summary>
        /// Add an item to the system menu.
        /// </summary>
        /// <param name="type">The type of the item.</param>
        /// <param name="text">The text of the item.</param>
        /// <returns>The item itself.</returns>
        public SystemMenuItem AddItem(SystemMenuItemType type, string text = "")
        {
            List <int> usedIDs = GetUsedIDs();
            int        id      = 0;

            while (usedIDs.Contains(id))
            {
                id++;
            }
            SystemMenuItem item = new SystemMenuItem(this, Menu, id);

            SysMenuAPI.AppendMenu(Menu, type == SystemMenuItemType.STRING ? SysMenuAPI.MenuTypes.MF_STRING : SysMenuAPI.MenuTypes.MF_SEPARATOR, id, text);
            Items.Add(item);
            return(item);
        }
        /// <summary>
        /// Add a item at a certain position to a sub menu of this item. This method will create a submenu if there is no one present.
        /// </summary>
        /// <param name="index">The index in the menu list the item should be added.</param>
        /// <param name="type">The type of the item.</param>
        /// <param name="text">The text of the item.</param>
        /// <returns>The item itself.</returns>
        public SystemMenuItem InsertSubItem(int index, SystemMenuItemType type, string text = "")
        {
            List <int> usedIDs = SysMenu.GetUsedIDs();
            int        id      = 0;

            while (usedIDs.Contains(id))
            {
                id++;
            }

            IntPtr p = SubMenu;

            if (p == IntPtr.Zero)
            {
                p       = SysMenuAPI.CreateMenu();
                SubMenu = p;
            }

            SystemMenuItem itm = new SystemMenuItem(SysMenu, p, id);

            SubItems.Insert(index, itm);
            SysMenuAPI.InsertMenu(p, index, SysMenuAPI.Flags.MF_BYPOSITION | (type == SystemMenuItemType.STRING ? SysMenuAPI.MenuTypes.MF_STRING : SysMenuAPI.MenuTypes.MF_SEPARATOR), id, text);
            return(itm);
        }
        /// <summary>
        /// Add a item to a sub menu of this item. This method will create a submenu if there is no one present.
        /// </summary>
        /// <param name="type">The type of the item.</param>
        /// <param name="text">The text of the item.</param>
        /// <returns>The item itself.</returns>
        public SystemMenuItem AddSubItem(SystemMenuItemType type, string text = "")
        {
            List <int> usedIDs = SysMenu.GetUsedIDs();
            int        id      = 0;

            while (usedIDs.Contains(id))
            {
                id++;
            }

            IntPtr p = SubMenu;

            if (p == IntPtr.Zero)
            {
                p       = SysMenuAPI.CreateMenu();
                SubMenu = p;
            }

            SystemMenuItem itm = new SystemMenuItem(SysMenu, p, id);

            SubItems.Add(itm);
            SysMenuAPI.AppendMenu(p, type == SystemMenuItemType.STRING ? SysMenuAPI.MenuTypes.MF_STRING : SysMenuAPI.MenuTypes.MF_SEPARATOR, id, text);
            return(itm);
        }