Example #1
0
        // SHSimpleIDListFromPath
        public static PidlData PIDListFromPath(string path)
        {
            var desktopFolder = DesktopFolder;
            var handle        = new PidlHandle(desktopFolder == null ? IntPtr.Zero
                : GetShellFolderChildrenPIDL(desktopFolder, path));

            return(new PidlData {
                Handle = handle
            });
        }
Example #2
0
        public bool InitFolder(IShellFolder folder, IntPtr itemPidl)
        {
            var relativePidl = ILShell32.ILFindLastID(itemPidl);

            if (comInterface != null && messageWindow != null)
            {
                return(true);
            }

            IntPtr result = IntPtr.Zero;

            IntPtr[] apidls = new IntPtr[] { itemPidl };

            var refGuid = typeof(IContextMenu).GUID;

            try
            {
                //PUIDLIST_RELATIVE ILFindChild(
                //  _In_ PCIDLIST_ABSOLUTE pidlParent,
                //  _In_ PCIDLIST_ABSOLUTE pidlChild
                //);

                PidlHandle handle   = new PidlHandle(relativePidl);
                var        itemPath = handle.Path;

                var relPidls = new IntPtr[] { relativePidl };

                folder.GetUIObjectOf(IntPtr.Zero,
                                     (uint)relPidls.Length,
                                     relPidls, // [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)]
                                     ref refGuid, 0, out result);

                if (result != IntPtr.Zero)
                {
                    comInterface = (IContextMenu)
                                   Marshal.GetTypedObjectForIUnknown(result,
                                                                     typeof(IContextMenu));

                    comInterface2 = comInterface as IContextMenu2;
                    comInterface3 = comInterface as IContextMenu3;
                    messageWindow = new MessageWindow(this);
                }
                else
                {
                    var handle2 = new PidlHandle(itemPidl);
                }
            }
            catch (Exception ex)
            {
                // Value does not fall within the expected range.
                this.LastError = ex;
            }

            return(result != IntPtr.Zero);
        }
Example #3
0
        public bool InitFolderPath(IShellFolder folder, IShellItem parent, IntPtr itemPidl, string path)
        {
            IntPtr pidl = itemPidl;

            if (path != null && Directory.Exists(path))     // if item is directory
            {
                IntPtr combine      = IntPtr.Zero;
                string parentFolder = Path.GetFullPath(path + @"\..");
                try
                {
                    // IntPtr result;
                    //var folderParent = (IShellFolder)Marshal.GetTypedObjectForIUnknown(result,
                    //    typeof(IShellFolder));
                    //ComAliasNameAttribute <

                    var parentPidl = ShPidlSystem.FromPath(parentFolder);
                    // clone = PidlClone.Of(itemPidl);

                    combine = ILShell32.ILCombine(parentPidl.Handle.pidl, itemPidl);

                    // ILShell32.ILRemoveLastID(combine);
                }
                catch (Exception ex)
                {
                    this.LastError = ex;
                }

                if (combine == IntPtr.Zero)
                {
                    return(false);
                }

                pidl = combine;
                var check = new PidlHandle(pidl);
            }

            return(InitFolder(folder, pidl));
        }