Exemplo n.º 1
0
        public void GetObjectTest()
        {
            using var f = new ShellFolder(testFld);
            using var i = new ShellItem(testFile);
            var qi = f.GetChildrenUIObjects <IQueryInfo>(null, i);

            Assert.That(qi, Is.Not.Null.And.InstanceOf <IQueryInfo>());
            System.Runtime.InteropServices.Marshal.ReleaseComObject(qi);
            var sv = f.GetViewObject <IShellView>(null);

            Assert.That(sv, Is.Not.Null.And.InstanceOf <IShellView>());
            Assert.That(() => f.GetChildrenUIObjects <IShellLibrary>(null, i), Throws.TypeOf <NotImplementedException>());
            Assert.That(() => f.GetViewObject <IShellLibrary>(null), Throws.TypeOf <NotImplementedException>());
        }
Exemplo n.º 2
0
        private static ContextMenu GetContextMenuForFolder(ShellFolder shellFolder, Shell32.CMF flags, Func <string, bool> itemFilter = null)
        {
            if (shellFolder == null)
            {
                return(null);
            }

            var sv = shellFolder.GetViewObject <Shell32.IShellView>(null);

            Shell32.IContextMenu menu = sv.GetItemObject <Shell32.IContextMenu>(Shell32.SVGIO.SVGIO_BACKGROUND);
            var hMenu = User32.CreatePopupMenu();

            menu.QueryContextMenu(hMenu, 0, 1, 0x7FFF, flags);
            var contextMenu = new ContextMenu(menu, hMenu, new[] { shellFolder.ParsingName });

            ContextMenu.EnumMenuItems(menu, hMenu, contextMenu.Items, itemFilter);
            return(contextMenu);
        }