示例#1
0
        internal static Dictionary <uint, MenuItemInfo> GetMenuItemInfo(IntPtr menu, IContextMenu contextMenu)
        {
            Dictionary <uint, MenuItemInfo> retVal = new Dictionary <uint, MenuItemInfo>();

            int totalItems = ShellAPI.GetMenuItemCount(menu);

            for (int i = 0; i < totalItems; i++)
            {
                uint          cmdID  = ShellAPI.GetMenuItemID(menu, i);
                StringBuilder textsb = new StringBuilder(256);
                ShellAPI.GetMenuString(menu, (uint)i, textsb, textsb.Capacity, ShellAPI.MF_BYPOSITION);

                string command = "";
                if (cmdID > 0 && cmdID <= ShellAPI.CMD_LAST)
                {
                    command = ContextMenuHelper.GetCommandString(
                        contextMenu, cmdID - ShellAPI.CMD_FIRST,
                        true);
                }

                retVal.Add((uint)i, new MenuItemInfo()
                {
                    RelativePosition = (uint)i, CommandID = cmdID, Text = textsb.ToString(), Command = command
                });
            }

            foreach (MenuItemInfo item in retVal.Values)
            {
                Debug.WriteLine(String.Format("{0} - {1} {2} ({3})", item.RelativePosition, item.CommandID, item.Command, item.Text));
            }

            return(retVal);
        }