public IDLWrapper GetItem(int idx, bool noAppend = false) { if (folderView == null) { return(new IDLWrapper()); } IntPtr ppidl = IntPtr.Zero; try { folderView.Item(idx, out ppidl); if (noAppend || ppidl == IntPtr.Zero) { return(new IDLWrapper(ppidl)); } using (IDLWrapper path = GetShellPath()) { return(new IDLWrapper(PInvoke.ILCombine(path.PIDL, ppidl))); } } finally { if (ppidl != IntPtr.Zero && !noAppend) { PInvoke.CoTaskMemFree(ppidl); } } }
void Test() { ShellWindows shellWindows = new ShellWindows(); try { foreach (IWebBrowser2 win in shellWindows) { WinAPI.IServiceProvider sp = win as WinAPI.IServiceProvider; object sb; sp.QueryService(SID_STopLevelBrowser, typeof(IShellBrowser).GUID, out sb); IShellBrowser shellBrowser = (IShellBrowser)sb; IShellView sv; shellBrowser.QueryActiveShellView(out sv); Console.WriteLine(win.LocationURL + " " + win.LocationName); IFolderView fv = sv as IFolderView; if (fv != null) { Timer t = new Timer(); t.Interval = 200; t.Tick += (o, se) => { int fitem; if (0 == fv.GetFocusedItem(out fitem)) { IntPtr pid; if (0 == fv.Item(fitem, out pid)) { //invokea(pid); } Marshal.FreeHGlobal(pid); } }; t.Start(); } } } catch (Exception ex) { Console.WriteLine(ex); } finally { if (shellWindows != null) { Marshal.ReleaseComObject(shellWindows); } } }
public static IntPtr Item(this IFolderView folderView, int index) { folderView.Item(index, out var pidl); return(pidl); }