示例#1
0
        public void CreateTest()
        {
            using var menu = new ShellContextMenu(new ShellItem(TestCaseSources.WordDoc));
            var items = menu.GetItems();

            for (var i = 0; i < items.Length; i++)
            {
                ShowMII(items[i], i);
            }
示例#2
0
        public void CreateTest()
        {
            using var shi  = ShellItem.Open(TestCaseSources.TempDir);
            using var menu = new ShellContextMenu(shi);
            var items = menu.GetItems(CMF.CMF_EXTENDEDVERBS | CMF.CMF_EXPLORE | CMF.CMF_CANRENAME | CMF.CMF_ITEMMENU);

            for (var i = 0; i < items.Length; i++)
            {
                ShowMII(items[i], i);
            }
        }
示例#3
0
        public static List <ContextMenuPackage> FetchContextMenuItems(string Path, bool FetchExtensionMenu = false)
        {
            try
            {
                if (File.Exists(Path) || Directory.Exists(Path))
                {
                    using (ShellItem Item = ShellItem.Open(Path))
                        using (ShellContextMenu ContextMenu = new ShellContextMenu(Item))
                        {
                            List <ContextMenuPackage> ContextMenuItemList = new List <ContextMenuPackage>();

                            foreach (var MenuItem in ContextMenu.GetItems(FetchExtensionMenu ? Shell32.CMF.CMF_EXPLORE | Shell32.CMF.CMF_EXTENDEDVERBS : Shell32.CMF.CMF_EXPLORE))
                            {
                                if (string.IsNullOrEmpty(MenuItem.Verb))
                                {
                                    continue;
                                }

                                switch (MenuItem.Verb.ToLower())
                                {
                                case "open":
                                case "opennewprocess":
                                case "pintohome":
                                case "cut":
                                case "copy":
                                case "paste":
                                case "delete":
                                case "properties":
                                case "openas":
                                case "link":
                                case "runas":
                                case "rename":
                                case "{e82bd2a8-8d63-42fd-b1ae-d364c201d8a7}":
                                {
                                    break;
                                }

                                default:
                                {
                                    if (!string.IsNullOrEmpty(MenuItem.HelpText))
                                    {
                                        if (MenuItem.BitmapHandle != HBITMAP.NULL)
                                        {
                                            using (Bitmap OriginBitmap = MenuItem.BitmapHandle.ToBitmap())
                                            {
                                                OriginBitmap.RotateFlip(RotateFlipType.RotateNoneFlipY);

                                                using (MemoryStream Stream = new MemoryStream())
                                                {
                                                    OriginBitmap.Save(Stream, ImageFormat.Png);

                                                    ContextMenuItemList.Add(new ContextMenuPackage(MenuItem.HelpText, MenuItem.Verb, Stream.ToArray()));
                                                }
                                            }
                                        }
                                        else
                                        {
                                            ContextMenuItemList.Add(new ContextMenuPackage(MenuItem.HelpText, MenuItem.Verb, Array.Empty <byte>()));
                                        }
                                    }

                                    break;
                                }
                                }
                            }

                            return(ContextMenuItemList);
                        }
                }
                else
                {
                    return(new List <ContextMenuPackage>(0));
                }
            }
            catch
            {
                return(new List <ContextMenuPackage>(0));
            }
        }