diff --git a/Greenshot/Forms/CaptureForm.cs b/Greenshot/Forms/CaptureForm.cs index 6adc7f00c..d4a9f0512 100644 --- a/Greenshot/Forms/CaptureForm.cs +++ b/Greenshot/Forms/CaptureForm.cs @@ -826,7 +826,7 @@ namespace Greenshot.Forms { if (_showDebugInfo && _selectedCaptureWindow != null) { - string title = string.Format("#{0:X}{1}{2}", _selectedCaptureWindow.Handle.ToInt64(), _selectedCaptureWindow.Text.Length > 0 ? " - ": "", _selectedCaptureWindow.Text); + string title = string.Format("#{0:X} - {1}", _selectedCaptureWindow.Handle.ToInt64(), _selectedCaptureWindow.Text.Length > 0 ? _selectedCaptureWindow.Text : _selectedCaptureWindow.Process.ProcessName); PointF debugLocation = new PointF(fixedRect.X, fixedRect.Y); graphics.DrawString(title, sizeFont, Brushes.DarkOrange, debugLocation); } diff --git a/Greenshot/Helpers/CaptureHelper.cs b/Greenshot/Helpers/CaptureHelper.cs index 6888d1777..f31c1e81e 100644 --- a/Greenshot/Helpers/CaptureHelper.cs +++ b/Greenshot/Helpers/CaptureHelper.cs @@ -461,9 +461,11 @@ namespace Greenshot.Helpers { return null; } - Thread getWindowDetailsThread = new Thread(RetrieveWindowDetails); - getWindowDetailsThread.Name = "Retrieve window details"; - getWindowDetailsThread.IsBackground = true; + Thread getWindowDetailsThread = new Thread(RetrieveWindowDetails) + { + Name = "Retrieve window details", + IsBackground = true + }; getWindowDetailsThread.Start(); return getWindowDetailsThread; } @@ -471,21 +473,7 @@ namespace Greenshot.Helpers { private void RetrieveWindowDetails() { LOG.Debug("start RetrieveWindowDetails"); // Start Enumeration of "active" windows - List allWindows = new List(WindowDetails.GetMetroApps()); - allWindows.AddRange(WindowDetails.GetAllWindows()); - foreach (WindowDetails window in allWindows) { - // Window should be visible and not ourselves - if (!window.Visible) { - continue; - } - - // Skip empty - Rectangle windowRectangle = window.WindowRectangle; - Size windowSize = windowRectangle.Size; - if (windowSize.Width == 0 || windowSize.Height == 0) { - continue; - } - + foreach (var window in WindowDetails.GetVisibleWindows()) { // Make sure the details are retrieved once window.FreezeDetails(); diff --git a/GreenshotPlugin/Core/WindowsHelper.cs b/GreenshotPlugin/Core/WindowsHelper.cs index 2cd6c4ba3..71db3675f 100644 --- a/GreenshotPlugin/Core/WindowsHelper.cs +++ b/GreenshotPlugin/Core/WindowsHelper.cs @@ -140,10 +140,11 @@ namespace GreenshotPlugin.Core { /// Provides details about a Window returned by the enumeration /// public class WindowDetails : IEquatable{ - private const string MetroWindowsClass = "Windows.UI.Core.CoreWindow"; // Windows 10 uses ApplicationFrameWindow + private const string MetroWindowsClass = "Windows.UI.Core.CoreWindow"; //Used for Windows 8(.1) + private const string FramedAppClass = "ApplicationFrameWindow"; // Windows 10 uses ApplicationFrameWindow private const string MetroApplauncherClass = "ImmersiveLauncher"; private const string MetroGutterClass = "ImmersiveGutter"; - private static readonly IList IgnoreClasses = new List(new[] { "Progman", "XLMAIN", "Button", "Dwm" }); //"MS-SDIa" + private static readonly IList IgnoreClasses = new List(new[] { "Progman", "Button", "Dwm" }); //"MS-SDIa" private static readonly ILog Log = LogManager.GetLogger(typeof(WindowDetails)); private static readonly CoreConfiguration Conf = IniConfig.GetIniSection(); @@ -187,6 +188,12 @@ namespace GreenshotPlugin.Core { /// public bool IsApp => MetroWindowsClass.Equals(ClassName); + /// + /// This checks if the window is a Windows 10 App + /// For Windows 10 apps are hosted inside "ApplicationFrameWindow" + /// + public bool IsWin10App => FramedAppClass.Equals(ClassName); + /// /// Check if the window is the metro gutter (sizeable separator) /// @@ -843,7 +850,7 @@ namespace GreenshotPlugin.Core { /// Point with the coordinates to check /// true if the point lies within public bool Contains(Point p) { - return WindowRectangle.Contains(Cursor.Position); + return WindowRectangle.Contains(p); } /// @@ -1484,6 +1491,13 @@ namespace GreenshotPlugin.Core { if (!Contains(point)) { return null; } + var rect = WindowRectangle; + // If the mouse it at the edge, take the whole window + if (rect.X == point.X || rect.Y == point.Y || rect.Right == point.X || rect.Bottom == point.Y) + { + return this; + } + // Look into the child windows foreach(var childWindow in Children) { if (childWindow.Contains(point)) { return childWindow.FindChildUnderPoint(point); @@ -1509,15 +1523,15 @@ namespace GreenshotPlugin.Core { /// /// /// - private static bool IsVisibleTopLevel(WindowDetails window, Rectangle screenBounds) + private static bool IsVisible(WindowDetails window, Rectangle screenBounds) { - // Ignore windows without title - if (window.Text.Length == 0) + // Ignore invisible + if (!window.Visible) { return false; } - // Ignore invisible - if (!window.Visible) + // Ignore minizied + if (window.Iconic) { return false; } @@ -1525,13 +1539,20 @@ namespace GreenshotPlugin.Core { { return false; } - // Windows without size - Rectangle windowRect = window.WindowRectangle; + // On windows which are visible on the screen + var windowRect = window.WindowRectangle; windowRect.Intersect(screenBounds); - if (windowRect.Size.IsEmpty) + if (windowRect.IsEmpty) { return false; } + // Skip everything which is not rendered "normally", trying to fix BUG-2017 + var exWindowStyle = window.ExtendedWindowStyle; + if (!window.IsApp && !window.IsWin10App && (exWindowStyle & ExtendedWindowStyleFlags.WS_EX_NOREDIRECTIONBITMAP) != 0) + { + return false; + } + return true; } @@ -1542,14 +1563,14 @@ namespace GreenshotPlugin.Core { public static IEnumerable GetVisibleWindows() { Rectangle screenBounds = WindowCapture.GetScreenBounds(); foreach(var window in GetMetroApps()) { - if (IsVisibleTopLevel(window, screenBounds)) + if (IsVisible(window, screenBounds)) { yield return window; } } foreach (var window in GetAllWindows()) { - if (IsVisibleTopLevel(window, screenBounds)) + if (IsVisible(window, screenBounds)) { yield return window; } @@ -1625,8 +1646,8 @@ namespace GreenshotPlugin.Core { { return false; } - // Skip everything which is not rendered "normally", trying to fix - if (!window.IsApp && (exWindowStyle & ExtendedWindowStyleFlags.WS_EX_NOREDIRECTIONBITMAP) != 0) + // Skip everything which is not rendered "normally", trying to fix BUG-2017 + if (!window.IsApp && !window.IsWin10App && (exWindowStyle & ExtendedWindowStyleFlags.WS_EX_NOREDIRECTIONBITMAP) != 0) { return false; }