public override object Suspend(SuspendInformation toSuspend) { var cabinetWindows = new ShellWindows() .Cast <InternetExplorer>() // TODO: Is there a safer way to guarantee that it is actually the explorer we expect it to be? // For some reason, the process CAN be both "Explorer", and "explorer". .Where(e => Path.GetFileNameWithoutExtension(e.FullName).IfNotNull(p => p.ToLower()) == "explorer") .ToList(); var suspendedExplorerWindows = new List <ExplorerLocation>(); foreach (Window window in toSuspend.Windows) { // Check whether the window is an explorer cabinet window. (file browser) InternetExplorer cabinetWindow = cabinetWindows.FirstOrDefault(e => { try { return(window.Handle.Equals(new IntPtr(e.HWND))); } catch (COMException) { // This exception is thrown when accessing 'HWND' for some windows. // TODO: Why is this the case, and do we ever need to handle those windows? return(false); } }); if (cabinetWindow != null) { var persistedData = new ExplorerLocation { LocationName = cabinetWindow.LocationName, LocationUrl = cabinetWindow.LocationURL, Pidl = cabinetWindow.GetPidl() }; cabinetWindow.Quit(); suspendedExplorerWindows.Add(persistedData); } // TODO: Support other explorer windows, e.g. property windows ... } return(suspendedExplorerWindows); }
public override object Suspend( SuspendInformation toSuspend ) { var cabinetWindows = new ShellWindows() .Cast<InternetExplorer>() // TODO: Is there a safer way to guarantee that it is actually the explorer we expect it to be? // For some reason, the process CAN be both "Explorer", and "explorer". .Where( e => Path.GetFileNameWithoutExtension( e.FullName ).IfNotNull( p => p.ToLower() ) == "explorer" ) .ToList(); var suspendedExplorerWindows = new List<ExplorerLocation>(); foreach ( Window window in toSuspend.Windows ) { // Check whether the window is an explorer cabinet window. (file browser) InternetExplorer cabinetWindow = cabinetWindows.FirstOrDefault( e => { try { return window.Handle.Equals( new IntPtr( e.HWND ) ); } catch ( COMException ) { // This exception is thrown when accessing 'HWND' for some windows. // TODO: Why is this the case, and do we ever need to handle those windows? return false; } } ); if ( cabinetWindow != null ) { var persistedData = new ExplorerLocation { LocationName = cabinetWindow.LocationName, LocationUrl = cabinetWindow.LocationURL, Pidl = cabinetWindow.GetPidl() }; cabinetWindow.Quit(); suspendedExplorerWindows.Add( persistedData ); } // TODO: Support other explorer windows, e.g. property windows ... } return suspendedExplorerWindows; }