コード例 #1
0
        private static IShellItemArray GetShellItemArray(string sourceFile)
        {
            IShellItem      item  = GetShellItem(sourceFile);
            IShellItemArray array = GetShellItemArray(item);

            return(array);
        }
コード例 #2
0
 private static IShellItemArray GetShellItemArray(IShellItem shellItem)
 {
     IShellItemArray iShellItemArray = null;
     Guid iIdIShellItemArray = new Guid("b63ea76d-1f85-456f-a19c-48159efa858b");
     SHCreateShellItemArrayFromShellItem(shellItem, iIdIShellItemArray, out iShellItemArray);
     return iShellItemArray;
 }
コード例 #3
0
        public static IReadOnlyList <String> GetFileNames(IShellItemArray items)
        {
            HResult hresult = items.GetCount(out UInt32 count);

            if (hresult != HResult.Ok)
            {
                throw new Exception("IShellItemArray.GetCount failed. HResult: " + hresult);                   // TODO: Will this ever happen?
            }
            else
            {
                List <String> list = new List <String>(capacity: (Int32)count);

                for (int i = 0; i < count; i++)
                {
#if NETCOREAPP3_1_OR_GREATER
                    IShellItem?shellItem = Utility.GetShellItemAt(items, i);
                    String?    fileName  = Utility.GetFileNameFromShellItem(shellItem);
#else
                    IShellItem shellItem = Utility.GetShellItemAt(items, i);
                    String     fileName  = Utility.GetFileNameFromShellItem(shellItem);
#endif
                    if (fileName != null)
                    {
                        list.Add(fileName);
                    }
                }

                return(list);
            }
        }
コード例 #4
0
 internal static IShellItem GetShellItemAt(IShellItemArray array, int i)
 {
     IShellItem result;
     uint index = (uint)i;
     array.GetItemAt(index, out result);
     return result;
 }
コード例 #5
0
        public static void SetSlidesIfNeeded(IDesktopWallpaper wallpaper, bool allways)
        {
            string          pname  = "";
            IShellItemArray slides = WinAPI.getImageItemsFromPath(images);
            IShellItemArray currentSlides;

            wallpaper.GetSlideshow(out currentSlides);
            IShellItem item, parent;

            currentSlides.GetItemAt(0, out item);
            if (item != null)
            {
                item.GetParent(out parent);
                parent.GetDisplayName(ShellNativeMethods.ShellItemDesignNameOptions.FileSystemPath, out pname);
            }
            string curpname = Path.GetTempPath();

            curpname = curpname.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
            pname    = pname.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
            if (curpname != pname || allways)
            {
                wallpaper.SetSlideshow(slides);
                wallpaper.SetSlideshowOptions(DesktopSlideshowDirection.Forward, ONEDAY_TICK);
            }
        }
コード例 #6
0
        /// <summary>
        /// Creates a ShellObject collection from an IShellItemArray
        /// </summary>
        /// <param name="iArray">IShellItemArray pointer</param>
        /// <param name="readOnly">Indicates whether the collection shouldbe read-only or not</param>
        internal ShellObjectCollection(IShellItemArray iArray, bool readOnly)
        {
            this.readOnly = readOnly;

            if (iArray != null)
            {
                try
                {
                    uint itemCount = 0;
                    iArray.GetCount(out itemCount);

                    content = new List <ShellObject>((int)itemCount);

                    for (uint index = 0; index < itemCount; index++)
                    {
                        IShellItem iShellItem = null;
                        iArray.GetItemAt(index, out iShellItem);
                        content.Add(ShellObjectFactory.Create(iShellItem));
                    }
                }
                finally
                {
                    Marshal.ReleaseComObject(iArray);
                }
            }
        }
コード例 #7
0
        internal IShellItem GetShellItemAt(IShellItemArray array, int i)
        {
            uint index = (uint)i;

            array.GetItemAt(index, out IShellItem result);
            return(result);
        }
コード例 #8
0
ファイル: ComUtility.cs プロジェクト: toras9000/CometFlavor
        /// <summary>
        /// シェルアイテム配列の各アイテムのファイルパスを列挙する
        /// </summary>
        /// <param name="items">シェルアイテム配列</param>
        /// <returns>ファイルパスのシーケンス</returns>
        public static IEnumerable <string> EnumerateItemPaths(IShellItemArray items)
        {
            // 配列内アイテムの個数を取得
            items.GetCount(out var itemCount);

            // 各アイテムからパスを取得
            for (uint i = 0; i < itemCount; i++)
            {
                var item = default(IShellItem);
                var path = default(string);
                try
                {
                    // 配列内のシェルアイテム取得
                    items.GetItemAt(i, out item);

                    // アイテムのパスを取得
                    path = GetFileSystemPath(item);
                }
                finally
                {
                    // シェルアイテムの参照を解放
                    ReleaseExistComObject(item);
                }

                // パスを列挙
                yield return(path);
            }
        }
コード例 #9
0
        public HRESULT CreatePlaylist(IShellItemArray psia)
        {
            _ppd = new IProgressDialog();
            _ppd.StartProgressDialog(dwFlags: PROGDLG.PROGDLG_AUTOTIME);
            _ppd.SetTitle("Building Playlist");
            _ppd.SetLine(1, "Finding music files...", false);

            var pnsw = new INamespaceWalk();

            pnsw.Walk(psia, NAMESPACEWALKFLAG.NSWF_TRAVERSE_STREAM_JUNCTIONS | NAMESPACEWALKFLAG.NSWF_DONT_ACCUMULATE_RESULT, 4, this);
            _fCountingFiles = false;
            _ppd.SetLine(1, "Adding files...", false);
            _pstm = _GetPlaylistStream();
            var hr = WriteHeader();

            if (hr.Succeeded)
            {
                pnsw.Walk(psia, NAMESPACEWALKFLAG.NSWF_TRAVERSE_STREAM_JUNCTIONS | NAMESPACEWALKFLAG.NSWF_DONT_ACCUMULATE_RESULT | NAMESPACEWALKFLAG.NSWF_SHOW_PROGRESS, 4, this);
                hr = WriteFooter();
            }

            _pstm.Commit(0);

            if (hr.Succeeded)
            {
                var psiCreated = _GetPlaylistItem <IShellItem>();
                hr = OpenFolderAndSelectItem(psiCreated);
            }
            _ppd.StopProgressDialog();
            _ExitMessageLoop();
            return(0);
        }
コード例 #10
0
        public static String[] GetFileNames(IShellItemArray items)
        {
            UInt32  count;
            HResult hresult = items.GetCount(out count);

            if (hresult != HResult.Ok)
            {
                throw new InvalidOperationException("IShellItemArray.GetCount failed. HResult: " + hresult);
            }

            String[] fileNames = new String[count];

            for (UInt32 i = 0; i < count; i++)
            {
                HResult result = items.GetItemAt(i, out IShellItem shellItem);
                if (result != HResult.Ok)
                {
                    throw new InvalidOperationException("IShellItemArray.GetItemAt( " + i + " ) failed. HResult: " + hresult);
                }

                String fileName = Utility.GetFileNameFromShellItem(shellItem);

                fileNames[i] = fileName;
            }

            return(fileNames);
        }
コード例 #11
0
        /// <summary>
        /// Gets the items in the ExplorerBrowser as an IShellItemArray
        /// </summary>
        /// <returns></returns>
        internal IShellItemArray GetItemsArray()
        {
            IShellItemArray iArray = null;
            IFolderView2    iFV2   = GetFolderView2();

            if (iFV2 != null)
            {
                try
                {
                    Guid    iidShellItemArray = new Guid(ShellIIDGuid.IShellItemArray);
                    object  oArray            = null;
                    HResult hr = iFV2.Items((uint)ShellViewGetItemObject.AllView, ref iidShellItemArray, out oArray);
                    if (hr != HResult.Ok &&
                        hr != HResult.Fail &&
                        hr != HResult.ElementNotFound &&
                        hr != HResult.InvalidArguments)
                    {
                        throw new CommonControlException(LocalizedMessages.ExplorerBrowserViewItems, hr);
                    }

                    iArray = oArray as IShellItemArray;
                }
                finally
                {
                    Marshal.ReleaseComObject(iFV2);
                    iFV2 = null;
                }
            }
            return(iArray);
        }
コード例 #12
0
        /// <summary>
        /// Gets the items in the ExplorerBrowser as an IShellItemArray
        /// </summary>
        /// <returns></returns>
        internal IShellItemArray GetItemsArray()
        {
            IShellItemArray iArray = null;
            IFolderView2    iFV2   = GetFolderView2();

            if (iFV2 != null)
            {
                try
                {
                    Guid    iidShellItemArray = new Guid(ShellIIDGuid.IShellItemArray);
                    object  oArray            = null;
                    HRESULT hr = iFV2.Items((uint)SVGIO.SVGIO_ALLVIEW, ref iidShellItemArray, out oArray);
                    if (hr != HRESULT.S_OK &&
                        hr != HRESULT.E_FAIL &&
                        hr != HRESULT.E_ELEMENTNOTFOUND &&
                        hr != HRESULT.E_INVALIDARG)
                    {
                        throw new COMException("unexpected error retrieving view items", (int)hr);
                    }

                    iArray = oArray as IShellItemArray;
                }
                finally
                {
                    Marshal.ReleaseComObject(iFV2);
                    iFV2 = null;
                }
            }
            return(iArray);
        }
コード例 #13
0
ファイル: ShellItemArray.cs プロジェクト: zuozhu315/Vanara
 /// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
 public virtual void Dispose()
 {
     if (array != null)
     {
         Marshal.ReleaseComObject(array);
         array = null;
     }
 }
コード例 #14
0
        static internal IShellItem GetShellItemAt(IShellItemArray array, int i)
        {
            IShellItem result;
            var        index = (uint)i;

            array.GetItemAt(index, out result);
            return(result);
        }
コード例 #15
0
        /// <summary>
        ///     Get <see cref="IShellItem" /> at the position specified by <see cref="index" />
        ///     from <see cref="IShellItemArray" />.
        /// </summary>
        /// <param name="shellItemArray"><see cref="IShellItemArray" />.</param>
        /// <param name="index">Index of the <see cref="IShellItemArray" />.</param>
        /// <returns><see cref="IShellItem" />.</returns>
        internal static IShellItem GetShellItemAt(IShellItemArray shellItemArray, int index)
        {
            Contract.Requires <ArgumentNullException>(shellItemArray != null);

            IShellItem result;

            shellItemArray.GetItemAt((uint)index, out result);
            return(result);
        }
コード例 #16
0
 // to make the verbs async capture the item array and post a message to do the work later
 public void CreatePlaylistAsync(uint msg, IShellItemArray psia)
 {
     // only allow one at a time
     if (_psia == null)
     {
         _psia = psia;
         PostThreadMessage(GetCurrentThreadId(), msg);
     }
 }
コード例 #17
0
ファイル: Utils.cs プロジェクト: dahall/WinClassicSamplesCS
        public static HRESULT DisplayItem(this IShellItemArray psia, HWND hwnd = default)
        {
            // Get the first ShellItem and display its name
            IShellItem psi            = psia.GetItemAt(0);
            var        pszDisplayName = psi.GetDisplayName(SIGDN.SIGDN_NORMALDISPLAY);

            User32.MessageBox(hwnd, pszDisplayName, pszDisplayName, User32.MB_FLAGS.MB_OK);
            return(HRESULT.S_OK);
        }
コード例 #18
0
 public static void PrintShellItemArray(IShellItemArray shellItemArray)
 {
     for (uint i = 0; i < shellItemArray.GetCount(); i++)
     {
         IShellItem si = shellItemArray.GetItemAt(i);
         Console.Out.WriteLine(si.GetDisplayName(SIGDN.SIGDN_FILESYSPATH));
         Marshal.ReleaseComObject(si);
     }
 }
コード例 #19
0
        /// <summary>
        ///     Get the number of items in <see cref="IShellItemArray" />.
        /// </summary>
        /// <param name="shellItemArray"><see cref="IShellItemArray" />.</param>
        /// <returns>Number of item.</returns>
        internal static int GetShellItemCount(IShellItemArray shellItemArray)
        {
            Contract.Requires <ArgumentNullException>(shellItemArray != null);

            uint result;

            shellItemArray.GetCount(out result);
            return((int)result);
        }
コード例 #20
0
 /// <summary>
 /// Copies items to a destination
 /// </summary>
 /// <param name="source">The items you want to copy</param>
 /// <param name="destination">The destination you want to copy the <paramref name="source"/> items</param>
 public void CopyItems(IShellItemArray source, IListItemEx destination)
 {
     this.ThrowIfDisposed();
     if (this._IsCopyInSameFolder)
     {
         this._FileOperation.SetOperationFlags(FileOperationFlags.FOF_RENAMEONCOLLISION | FileOperationFlags.FOF_ALLOWUNDO | FileOperationFlags.FOF_NOCONFIRMMKDIR);
     }
     this._FileOperation.CopyItems(source, destination.ComInterface);
 }
コード例 #21
0
        private static IEnumerable <string> ConvertShellItemArray(IShellItemArray itemArray)
        {
            itemArray.GetCount(out var count);
            string[] paths = new string[count];

            for (int i = 0; i < count; i++)
            {
                itemArray.GetItemAt(i, out IShellItem item);
                item.GetDisplayName(SIGDN.FILESYSPATH, out var name);
                paths[i] = name;
            }

            return(paths);
        }
コード例 #22
0
 private static void Main(string[] args)
 {
     ApplicationActivationManager appActiveManager = new ApplicationActivationManager();//Class not registered
     uint pid;
     appActiveManager.ActivateApplication("2c123c17-8b21-4eb8-8b7f-fdc35c8b7718_n2533ggrncqjt!App", null, ActivateOptions.None, out pid);
     Console.WriteLine("Activated");
     Console.ReadLine();
     
     IShellItemArray array = GetShellItemArray(@"C:\temp\somefile.xyz");
     appActiveManager.ActivateForFile("2c123c17-8b21-4eb8-8b7f-fdc35c8b7718_n2533ggrncqjt!App", array, "Open",
         out pid);
     Console.WriteLine("Activated for file");
     Console.ReadLine();
 }
コード例 #23
0
        public static void GetSlideShow(string[] paths)
        {
            // Load into memory
            DesktopWallpaper.IDesktopWallpaper wallpaper = DesktopWallpaper.WallpaperWrapper.GetWallpaper();
            IShellItemArray slideshow = wallpaper.GetSlideshow();
            IShellItemArray pictures  = FoldersToShellItemArray(paths);

            Console.Out.WriteLine("Now: ");
            PrintShellItemArray(slideshow);
            Console.Out.WriteLine("Program: ");
            PrintShellItemArray(pictures);

            // Cleanup
            Marshal.ReleaseComObject(pictures);
            Marshal.ReleaseComObject(slideshow);
            Marshal.ReleaseComObject(wallpaper);
        }
コード例 #24
0
ファイル: ComHelper.cs プロジェクト: ebmoluoc/CsharpHelpers
        /// <summary>
        /// Gets all the ShellItems from ShellItemArray.
        /// </summary>
        /// <exception cref="COMException">See HRESULT value for more details.</exception>
        public static IShellItem[] GetShellItems(IShellItemArray shellItemArray)
        {
            shellItemArray.GetCount(out var count);
            var shellItems = new IShellItem[count];

            // TODO: getting all the items in one go might not be a good idea - but when could it fails?
            shellItemArray.EnumItems(out var enumShellItems);
            var hresult = enumShellItems.Next(count, shellItems, out var fetched);

            Marshal.ReleaseComObject(enumShellItems);

            if (hresult != HRESULT.S_OK || count != fetched)
            {
                throw new COMException("Unexpected error from IEnumShellItems::Next.", hresult.Value);
            }

            return(shellItems);
        }
コード例 #25
0
        public static IShellItem GetShellItemAt(IShellItemArray array, int i)
#endif
        {
            if (array is null)
            {
                throw new ArgumentNullException(nameof(array));
            }

            HResult hr = array.GetItemAt((UInt32)i, out IShellItem result);

            if (hr == HResult.Ok)
            {
                return(result);
            }
            else
            {
                return(null);
            }
        }
コード例 #26
0
        public static String[] GetFileNames(IShellItemArray items)
        {
            UInt32  count;
            HResult hresult = items.GetCount(out count);

            if (hresult != HResult.Ok)
            {
                throw new Exception("IShellItemArray.GetCount failed. HResult: " + hresult);                                       // TODO: Will this ever happen?
            }
            String[] fileNames = new String[count];

            for (int i = 0; i < count; i++)
            {
                IShellItem shellItem = Utility.GetShellItemAt(items, i);
                String     fileName  = Utility.GetFileNameFromShellItem(shellItem);

                fileNames[i] = fileName;
            }

            return(fileNames);
        }
コード例 #27
0
 internal override string[] ProcessVistaFiles(IFileDialog dialog)
 {
     var openDialog = (IFileOpenDialog)dialog;
     if (Multiselect)
     {
         IShellItemArray results = openDialog.GetResults();
         uint count = results.GetCount();
         string[] paths = new string[count];
         for (uint i = 0; i < count; ++i)
         { 
             IShellItem item = results.GetItemAt(i);
             paths[i] = item.GetDisplayName(SIGDN.DESKTOPABSOLUTEPARSING);
         }
         return paths;
     }
     else
     { 
         IShellItem item = openDialog.GetResult();
         return new [] { item.GetDisplayName(SIGDN.DESKTOPABSOLUTEPARSING) };
     }
 }
コード例 #28
0
        public static void ActivateForFile(string appUserModelId, string filePullPath, string verb, bool waitForExit = false)
        {
            ApplicationActivationManager appActiveManager = new ApplicationActivationManager();//Class not registered
            IShellItemArray array = GetShellItemArray(filePullPath);

            uint pid;
            CommonHRESULTValues result = (CommonHRESULTValues)appActiveManager.ActivateForFile(appUserModelId, array, verb, out pid);

            if (result == CommonHRESULTValues.S_OK)
            {
                if (waitForExit)
                {
                    Process process = Process.GetProcessById((int)pid);
                    process.WaitForExit();
                }
            }
            else
            {
                throw new Exception("ActivateForFile failed error code: " + result);
            }
        }
コード例 #29
0
 /// <summary>Gets the <see cref="ShellItem"/> at the specified index.</summary>
 /// <value>The <see cref="ShellItem"/>.</value>
 /// <param name="index">The zero-based index of the element to get.</param>
 public ShellItem this[int index]
 {
     get
     {
         IShellItemArray array = Array;
         try
         {
             return(array is null ? null : ShellItem.Open(array.GetItemAt((uint)index)));
         }
         catch
         {
             return(null);
         }
         finally
         {
             if (array is not null)
             {
                 Marshal.ReleaseComObject(array);
             }
         }
     }
 }
コード例 #30
0
        /// <summary>
        /// Converts an <see cref="IShellItemArray"/> into a IShellItem[]
        /// </summary>
        /// <param name="shellItemArray">The Interface you want to convert</param>
        /// <returns></returns>
        public static IShellItem[] ToArray(this IShellItemArray shellItemArray)
        {
            var items = new List <IShellItem>();

            if (shellItemArray == null)
            {
                return(items.ToArray());
            }
            try {
                uint itemCount = 0;
                shellItemArray.GetCount(out itemCount);
                for (uint index = 0; index < itemCount; index++)
                {
                    IShellItem iShellItem = null;
                    shellItemArray.GetItemAt(index, out iShellItem);
                    items.Add(iShellItem);
                }
            } finally {
                //Marshal.ReleaseComObject(shellItemArray);
            }
            return(items.ToArray());
        }
コード例 #31
0
 internal IShellItem GetShellItemAt(IShellItemArray array, int i)
 {
     IShellItem result;
     uint index = (uint)i;
     array.GetItemAt(index, out result);
     return result;
 }