示例#1
0
        TreeNode InsertNode(TreeNode parent, ShellItem folder, string displayName)
        {
            ShellItem parentFolder  = (ShellItem)parent.Tag;
            IntPtr    folderRelPidl = Shell32.ILFindLastID(folder.Pidl);
            TreeNode  result        = null;

            foreach (TreeNode child in parent.Nodes)
            {
                ShellItem childFolder  = (ShellItem)child.Tag;
                IntPtr    childRelPidl = Shell32.ILFindLastID(childFolder.Pidl);
                short     compare      = parentFolder.GetIShellFolder().CompareIDs(0,
                                                                                   folderRelPidl, childRelPidl);

                if (compare < 0)
                {
                    result = parent.Nodes.Insert(child.Index, displayName);
                    break;
                }
            }

            if (result == null)
            {
                result = parent.Nodes.Add(displayName);
            }

            return(result);
        }
示例#2
0
        static IShellView CreateViewObject(ShellItem folder, IntPtr hwndOwner)
        {
            IntPtr result = folder.GetIShellFolder().CreateViewObject(hwndOwner,
                                                                      typeof(IShellView).GUID);

            return((IShellView)
                   Marshal.GetTypedObjectForIUnknown(result,
                                                     typeof(IShellView)));
        }
示例#3
0
        void Initialize(ShellItem[] items)
        {
            IntPtr[]  pidls  = new IntPtr[items.Length];
            ShellItem parent = null;
            IntPtr    result;

            for (int n = 0; n < items.Length; ++n)
            {
                pidls[n] = Shell32.ILFindLastID(items[n].Pidl);

                if (parent == null)
                {
                    if (items[n] == ShellItem.Desktop)
                    {
                        parent = ShellItem.Desktop;
                    }
                    else
                    {
                        parent = items[n].Parent;
                    }
                }
                else
                {
                    if (items[n].Parent != parent)
                    {
                        throw new Exception("All shell items must have the same parent");
                    }
                }
            }

            parent.GetIShellFolder().GetUIObjectOf(IntPtr.Zero,
                                                   (uint)pidls.Length, pidls,
                                                   typeof(IContextMenu).GUID, 0, out result);
            m_ComInterface = (IContextMenu)
                             Marshal.GetTypedObjectForIUnknown(result,
                                                               typeof(IContextMenu));
            m_ComInterface2 = m_ComInterface as IContextMenu2;
            m_ComInterface3 = m_ComInterface as IContextMenu3;
            m_MessageWindow = new MessageWindow(this);
        }