Beispiel #1
0
        private List <int> RecursiveIDGetter(SystemMenuItem item)
        {
            List <int> usedIds = new List <int>();

            usedIds.Add(item.ID);
            foreach (SystemMenuItem itm in item.GetSubItems())
            {
                usedIds.AddRange(RecursiveIDGetter(itm));
            }
            return(usedIds);
        }
Beispiel #2
0
 private SystemMenuItem RecursivePath(SystemMenuItem parent, int[] path, int pathIndex)
 {
     if (path.Length == pathIndex + 1)
     {
         return(parent.GetSubItems()[path[pathIndex]]);
     }
     else
     {
         return(RecursivePath(parent.GetSubItems()[path[pathIndex]], path, pathIndex + 1));
     }
 }
        /// <summary>
        /// Remove an item from the sub menu.
        /// </summary>
        /// <param name="index">The index of the item which should be removed.</param>
        public void RemoveSubItem(int index)
        {
            SystemMenuItem itm = SubItems[index];

            SysMenuAPI.RemoveMenu(itm.HMenu, itm.ID, SysMenuAPI.Flags.MF_BYCOMMAND);
            if (itm.HasSubItems())
            {
                itm.ClearSubMenu();
            }
            SubItems.RemoveAt(index);
            if (SubItems.Count == 0)
            {
                SubMenu = IntPtr.Zero;
            }
        }
Beispiel #4
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);
        }
Beispiel #5
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);
        }
 public SystemItemEventArgs(SystemMenuItem item)
 {
     Item = item;
 }
Beispiel #9
0
 public void Item_Click(SystemMenuItem item)
 {
     MessageBox.Show(item.ToString());
 }
Beispiel #10
0
        /**
         *  PRESETS
         */
        public void UsePreset_ExtendedMenu(Action mainMenu    = null, string mainmenu_Text    = "Menu",
                                           Action help        = null, string help_Text        = "Help",
                                           Action topMost     = null, string topMost_Text     = "Window always on top",
                                           Action fullscreen  = null, string fullscreen_Text  = "Toggle fullscreen",
                                           Action info        = null, string info_Text        = "About",
                                           Action commandMenu = null, string commandMenu_Text = "Tools")
        {
            if (mainMenu != null)
            {
                SystemMenuItem item = InsertItem(SystemMenuItemType.STRING, 0, mainmenu_Text);
                item.SetSystemIcon(SysMenuAPI.MenuItemInfo_hItem.HBMMENU_SYSTEM);
                item.Click += (s1, e1) =>
                {
                    mainMenu();
                };
                InsertItem(SystemMenuItemType.SEPARATOR, 1);
            }

            if (help != null || topMost != null || fullscreen != null || info != null || commandMenu != null)
            {
                InsertItem(SystemMenuItemType.SEPARATOR, ItemCount() - 2);
            }

            if (help != null)
            {
                SystemMenuItem item = InsertItem(SystemMenuItemType.STRING, ItemCount() - 2, help_Text);
                item.Click += (s1, e1) =>
                {
                    help();
                };
            }

            if (info != null)
            {
                SystemMenuItem item = InsertItem(SystemMenuItemType.STRING, ItemCount() - 2, info_Text);
                item.Click += (s1, e1) =>
                {
                    info();
                };
            }

            if (topMost != null)
            {
                SystemMenuItem item = InsertItem(SystemMenuItemType.STRING, ItemCount() - 2, topMost_Text);
                item.Click += (s1, e1) =>
                {
                    topMost();
                };
            }

            if (fullscreen != null)
            {
                SystemMenuItem item = InsertItem(SystemMenuItemType.STRING, ItemCount() - 2, fullscreen_Text);
                item.Click += (s1, e1) =>
                {
                    fullscreen();
                };
            }

            if (commandMenu != null)
            {
                SystemMenuItem item = InsertItem(SystemMenuItemType.STRING, ItemCount() - 2, commandMenu_Text);
                item.Click += (s1, e1) =>
                {
                    commandMenu();
                };
            }
        }