private static IShellItemArray GetShellItemArray(string sourceFile) { IShellItem item = GetShellItem(sourceFile); IShellItemArray array = GetShellItemArray(item); return(array); }
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; }
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); } }
internal static IShellItem GetShellItemAt(IShellItemArray array, int i) { IShellItem result; uint index = (uint)i; array.GetItemAt(index, out result); return result; }
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); } }
/// <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); } } }
internal IShellItem GetShellItemAt(IShellItemArray array, int i) { uint index = (uint)i; array.GetItemAt(index, out IShellItem result); return(result); }
/// <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); } }
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); }
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); }
/// <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); }
/// <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); }
/// <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; } }
static internal IShellItem GetShellItemAt(IShellItemArray array, int i) { IShellItem result; var index = (uint)i; array.GetItemAt(index, out result); return(result); }
/// <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); }
// 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); } }
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); }
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); } }
/// <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); }
/// <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); }
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); }
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(); }
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); }
/// <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); }
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); } }
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); }
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) }; } }
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); } }
/// <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); } } } }
/// <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()); }
internal IShellItem GetShellItemAt(IShellItemArray array, int i) { IShellItem result; uint index = (uint)i; array.GetItemAt(index, out result); return result; }