public void ShellTest() { var shellWindows = new ShellWindows(); foreach (IWebBrowser2 win in shellWindows) { IServiceProvider sp = win as IServiceProvider; object sb; sp.QueryService(SID_STopLevelBrowser, typeof(IShellBrowser).GUID, out sb); IShellBrowser shellBrowser = (IShellBrowser)sb; object sv; shellBrowser.QueryActiveShellView(out sv); Console.WriteLine(win.LocationURL + " " + win.LocationName); IFolderView fv = sv as IFolderView; if (fv != null) { // only folder implementation support this (IE windows do not for example) object pf; fv.GetFolder(typeof(IPersistFolder2).GUID, out pf); IPersistFolder2 persistFolder = (IPersistFolder2)pf; // get folder class, for example // CLSID_ShellFSFolder for standard explorer folders Guid clsid; persistFolder.GetClassID(out clsid); Console.WriteLine(" clsid:" + clsid); int pitem; Timer timer = new Timer(new TimerCallback(stat => { //if (0 == fv.GetFocusedItem(out pitem)) //{ // Console.WriteLine(pitem); //} if (0 == fv.ItemCount(0x00000001, out pitem)) { Console.WriteLine(pitem); } })); timer.Change(200, 0); // get current folder pidl IntPtr pidl; persistFolder.GetCurFolder(out pidl); // TODO: do something with pidl Marshal.FreeCoTaskMem(pidl); // free pidl's allocated memory } } }
public int GetItemCount() { int count; return(folderView != null && folderView.ItemCount(SVGIO.ALLVIEW, out count) == 0 ? count : 0); }