コード例 #1
0
        public void GetPCChildItems()
        {
            int iCnt = 0;

            foreach (var item in Browser.GetChildItems(KF_IID.ID_FOLDERID_ComputerFolder))
            {
                // First item is null if we are looking at an item under the desktop item
                var fullIdList = (item.ParentIdList != null ?
                                  PidlManager.Combine(item.ParentIdList, item.ChildIdList) :
                                  item.ChildIdList);

                IKnownFolderProperties props = null;
                using (var kf = KnownFolderHelper.FromPIDL(fullIdList))
                {
                    if (kf != null)
                    {
                        props = KnownFolderHelper.GetFolderProperties(kf.Obj);
                        Assert.IsTrue(props != null);
                    }
                }

                Assert.IsTrue(item != null);
                iCnt++;
            }

            Assert.IsTrue(iCnt > 0);
        }
コード例 #2
0
        private void OnOpen(object sender, EventArgs eventArgs)
        {
            SHELLEXECUTEINFO sei = new SHELLEXECUTEINFO();

            sei.cbSize = Marshal.SizeOf(sei);
            sei.fMask  = SEE.SEE_MASK_IDLIST | SEE.SEE_MASK_CLASSNAME;
            var fullPidl = PidlManager.IdListToPidl(PidlManager.Combine(_folderIdList, _folderItemIdLists[0]));

            sei.lpIDList = fullPidl;
            sei.lpClass  = "folder";
            sei.hwnd     = CurrentInvokeCommandInfo.WindowHandle;
            sei.nShow    = CurrentInvokeCommandInfo.ShowCommand;
            sei.lpVerb   = "open"; // todo parameter open.
            Shell32.ShellExecuteEx(ref sei);
            PidlManager.DeletePidl(fullPidl);
        }
コード例 #3
0
        public static void OpenSystemMenu(ShellItem itemHit, Control ctrl, int x, int y)
        {
            //  The shell folder we use to get the UI object is either the folder itself if the
            //  item is a folder, or the parent folder otherwise.
            var shellFolder = itemHit.IsFolder ? itemHit.ShellFolderInterface : itemHit.ParentItem.ShellFolderInterface;

            //  The item pidl is either the folder if the item is a folder, or the combined pidl otherwise.
            var fullIdList = itemHit.IsFolder
                ? PidlManager.PidlToIdlist(itemHit.PIDL)
                : PidlManager.Combine(
                PidlManager.PidlToIdlist(itemHit.ParentItem.PIDL),
                PidlManager.PidlToIdlist(itemHit.RelativePIDL));


            //  Get the UI object of the context menu.
            IntPtr[] apidl = new IntPtr[] { PidlManager.IdListToPidl(fullIdList) };
            // PidlManager.PidlsToAPidl(new IntPtr[] { PidlManager.IdListToPidl(fullIdList) });

            IntPtr ppv = IntPtr.Zero;

            shellFolder.GetUIObjectOf(ctrl.Handle, 1,
                                      apidl,
                                      Shell32.IID_IContextMenu, 0,
                                      out ppv);

            //  If we have an item, cast it.
            if (ppv != IntPtr.Zero)
            {
                // desktop menu
                var contextMenu = Marshal.GetObjectForIUnknown(ppv) as IContextMenu; // IContextMenuSharp

                var popupMenu = new ContextMenu();
                contextMenu.QueryContextMenu(popupMenu.Handle, 0, 0, 65525, CMF.CMF_EXPLORE);
                popupMenu.Show(ctrl, new Point(x, y));
                return;
            }
        }
コード例 #4
0
ファイル: ShellTreeView.cs プロジェクト: zhang024/sharpshell
        private void OpenItemContextMenu(ShellItem itemHit, int x, int y)
        {
            //  TODO: we need a min and max for the menu items.

            //  see http://www.codeproject.com/Articles/4025/Use-Shell-ContextMenu-in-your-applications for more

            //  The shell folder we use to get the UI object is either the folder itself if the
            //  item is a folder, or the parent folder otherwise.
            var shellFolder = itemHit.IsFolder ? itemHit.ShellFolderInterface : itemHit.ParentItem.ShellFolderInterface;

            //  The item pidl is either the folder if the item is a folder, or the combined pidl otherwise.
            var fullIdList = itemHit.IsFolder
                ? PidlManager.PidlToIdlist(itemHit.PIDL)
                : PidlManager.Combine(PidlManager.PidlToIdlist(itemHit.ParentItem.PIDL),
                                      PidlManager.PidlToIdlist(itemHit.RelativePIDL));


            //  Get the UI object of the context menu.
            IntPtr apidl = PidlManager.PidlsToAPidl(new IntPtr[] { PidlManager.IdListToPidl(fullIdList) });


            IntPtr ppv = IntPtr.Zero;

            shellFolder.GetUIObjectOf(Handle, 1, apidl, Shell32.IID_IContextMenu, 0,
                                      out ppv);

            //  If we have an item, cast it.
            if (ppv != IntPtr.Zero)
            {
                IContextMenu contextMenu = (IContextMenu)Marshal.GetObjectForIUnknown(ppv);

                var popupMenu = new ContextMenu();
                contextMenu.QueryContextMenu(popupMenu.Handle, 0, 0, 65525, CMF.CMF_EXPLORE);
                popupMenu.Show(this, new Point(x, y));
            }
        }