/// <summary> /// Gets the desktop window in which desktop icons are displayed. /// </summary> /// <returns></returns> public static WindowInfo GetDesktopWindow() { Func<WindowInfo, WindowInfo> findDesktopShell = w => w.GetChildWindows().FirstOrDefault( c => c.GetClassName() == "SHELLDLL_DefView" ); // Before Windows 7, the desktop window could generally be found as a direct child of the shell. var shellWindow = new WindowInfo( User32.GetShellWindow() ); if ( shellWindow == null ) { throw new InvalidOperationException( "No Shell process is present." ); } var desktop = findDesktopShell( shellWindow ); if ( desktop != null ) { return desktop; } // Windows 7 can have cycling wallpapers enabled, in which case the desktop window can be found in a window with class "WorkerW". var workerWindows = GetWindows().Where( w => w.GetClassName() == "WorkerW" ); foreach ( WindowInfo w in workerWindows ) { desktop = findDesktopShell( w ); if ( desktop != null ) { return desktop; } } throw new NotSupportedException( "Could not find desktop window where it was expected." ); }
public WindowViewModel( WindowInfo window ) { Window = window; Process process = window.GetProcess(); ProcessName = process?.ProcessName ?? "Not Found!"; CompanyName = process?.MainModule.FileVersionInfo.CompanyName ?? ""; ClassName = window.GetClassName(); Title = window.GetTitle(); IsVisible = window.IsVisible(); }
/// <summary> /// Creates a new snapshot for a window currently visible on the open desktop. /// This constructor should only be called on windows assigned to a currently visible desktop. /// </summary> /// <param name="currentDesktop">The desktop the window is assigned to.</param> /// <param name="info">The open window</param> internal WindowSnapshot( VirtualDesktop currentDesktop, WindowInfo info ) { if ( !currentDesktop.IsVisible ) { throw new InvalidOperationException( "Window snapshots can only be created when the desktop the window belongs to is currently visible." ); } Desktop = currentDesktop; Info = info; Update(); }
public RepositionWindowInfo( WindowInfo toPosition ) { ToPosition = toPosition; _originalVisible = toPosition.IsVisible(); Visible = _originalVisible; var placement = new User32.WindowPlacement(); User32.GetWindowPlacement( toPosition.Handle, ref placement ); User32.Rectangle position = placement.NormalPosition; _originalX = position.Left; X = _originalX; _originalY = position.Top; Y = _originalY; // TODO: According to the documentation, the pixel at (right, bottom) lies immediately outside the rectangle. Do we need to subtract with 1? _originalWidth = position.Right - position.Left; Width = _originalWidth; _originalHeight = position.Bottom - position.Top; Height = _originalHeight; }
public Window( WindowInfo windowInfo ) { WindowInfo = windowInfo; }
/// <summary> /// Find the next window below the specified window. /// </summary> /// <returns>The next window below the specified window, or null when the specified window is at the bottom.</returns> public static WindowInfo GetWindowBelow( WindowInfo window ) { IntPtr windowHandle = User32.GetWindow( window.Handle, User32.WindowRelationship.Next ); return windowHandle == IntPtr.Zero ? null : new WindowInfo( windowHandle ); }
public bool Equals( WindowInfo other ) { if ( ReferenceEquals( null, other ) ) { return false; } return ReferenceEquals( this, other ) || other.Handle.Equals( Handle ); }
ApplicationBehaviorsProcess GetProcessSettings( WindowInfo window ) { // See whether settings are cached. if ( _accessDeniedWindows.Contains( window ) ) { return _dontHandleProcess; } if ( _windowProcessBehaviors.ContainsKey( window ) ) { return _windowProcessBehaviors[ window ]; } // Prevent cached settings from being kept in memory when windows are destroyed. var deniedToRemove = _accessDeniedWindows.Where( w => w.IsDestroyed() ).ToArray(); deniedToRemove.ForEach( w => _accessDeniedWindows.Remove( w ) ); var processBehaviorsToRemove = _windowProcessBehaviors.Where( p => p.Key.IsDestroyed() ).ToArray(); processBehaviorsToRemove.ForEach( p => _windowProcessBehaviors.Remove( p.Key ) ); // Get settings. Process process = window.GetProcess(); try { // Find matching settings based on process file info. var matches = _settings.Process.Where( p => new TargetProcess( p.Name, p.CompanyName, p.Version ).Matches( process ) ).ToList(); // Select the most optimal match, or handle the process by default when no match found. ApplicationBehaviorsProcess processBehavior = matches.Count == 0 ? _handleProcess : matches.MaxBy( p => p.Version?.Length ?? 0 ); // Longest version number that matches is most 'specific'. _windowProcessBehaviors[ window ] = processBehavior; return processBehavior; } catch ( Win32Exception ) { _accessDeniedWindows.Add( window ); return _dontHandleProcess; } }
public bool Equals( WindowInfo window ) { return ClassName == window.GetClassName() && ( Visible == WindowVisible.Both || ( window.IsVisible() && Visible == WindowVisible.True ) ) && ( Title == null || window.GetTitle() == Title ); }
public IEnumerable<WindowInfo> ToCut( WindowInfo windowInfo, VirtualDesktopManager desktopManager ) { var searchWindows = CutHelper.WindowsToSearchIn( desktopManager, ConsiderWindows ); return searchWindows.Where( s => Window.Any( w => w.Equals( s ) ) ); }
public IEnumerable<WindowInfo> ToCut( WindowInfo windowInfo, VirtualDesktopManager desktopManager ) { var windows = new List<WindowInfo>(); switch ( Hide ) { case ApplicationBehaviorsProcessHideBehaviorDefaultHide.SelectedWindow: { windows.Add( windowInfo ); break; } case ApplicationBehaviorsProcessHideBehaviorDefaultHide.AllProcessWindows: { var searchWindows = CutHelper.WindowsToSearchIn( desktopManager, ConsiderWindows ); var processWindows = searchWindows.Where( w => { Process cutProcess = windowInfo.GetProcess(); Process otherProcess = w.GetProcess(); return cutProcess != null && otherProcess != null && cutProcess.Id == otherProcess.Id; } ); windows.AddRange( processWindows ); break; } } return windows; }