diff --git a/Greenshot/Forms/MainForm.cs b/Greenshot/Forms/MainForm.cs index ab6f3353c..e72a2ec44 100644 --- a/Greenshot/Forms/MainForm.cs +++ b/Greenshot/Forms/MainForm.cs @@ -316,8 +316,6 @@ namespace Greenshot { public MainForm(CopyDataTransport dataTransport) { instance = this; - // Make sure we never capture the mainform - WindowDetails.RegisterIgnoreHandle(this.Handle); // // The InitializeComponent() call is required for Windows Forms designer support. // @@ -369,6 +367,9 @@ namespace Greenshot { // Setting it to true this late prevents Problems with the context menu notifyIcon.Visible = !conf.HideTrayicon; + // Make sure we never capture the mainform + WindowDetails.RegisterIgnoreHandle(this.Handle); + // Create a new instance of the class: copyData = new CopyData(); copyData = new CopyData(); @@ -799,8 +800,8 @@ namespace Greenshot { menuItem.DropDownItems.Clear(); // check if thumbnailPreview is enabled and DWM is enabled bool thumbnailPreview = conf.ThumnailPreview && DWM.isDWMEnabled(); - - List windows = WindowDetails.GetVisibleWindows(); + + List windows = WindowDetails.GetTopLevelWindows(); foreach(WindowDetails window in windows) { ToolStripMenuItem captureWindowItem = new ToolStripMenuItem(window.Text); captureWindowItem.Tag = window; diff --git a/GreenshotPlugin/Core/WindowsHelper.cs b/GreenshotPlugin/Core/WindowsHelper.cs index 93b355b9d..5337df9d2 100644 --- a/GreenshotPlugin/Core/WindowsHelper.cs +++ b/GreenshotPlugin/Core/WindowsHelper.cs @@ -579,7 +579,8 @@ namespace GreenshotPlugin.Core { public bool HasParent { get { - return !IntPtr.Zero.Equals(parentHandle); + GetParent(); + return parentHandle != IntPtr.Zero; } } @@ -1477,12 +1478,8 @@ namespace GreenshotPlugin.Core { if (!window.Visible) { continue; } - // Ignore internal windows - if (ignoreHandles.Contains(window.Handle)) { - continue; - } // Ignore some classes - List ignoreClasses = new List(new string[] {"Progman", "XLMAIN", "Button"}); //"MS-SDIa" + List ignoreClasses = new List(new string[] { "Progman", "XLMAIN", "Button", "Dwm" }); //"MS-SDIa" if (ignoreClasses.Contains(window.ClassName)) { continue; } @@ -1497,6 +1494,42 @@ namespace GreenshotPlugin.Core { return windows; } + /// + /// Get all the top level windows + /// + /// List with all the top level windows + public static List GetTopLevelWindows() { + List windows = new List(); + Rectangle screenBounds = WindowCapture.GetScreenBounds(); + List allWindows = WindowDetails.GetAllWindows(); + foreach (WindowDetails window in allWindows) { + // Ignore windows without title + if (window.Text.Length == 0) { + continue; + } + // Ignore some classes + List ignoreClasses = new List(new string[] { "Progman", "XLMAIN", "Button", "Dwm" }); //"MS-SDIa" + if (ignoreClasses.Contains(window.ClassName)) { + continue; + } + // Windows without size + if (window.WindowRectangle.Size.IsEmpty) { + continue; + } + if (window.HasParent) { + continue; + } + if ((window.ExtendedWindowStyle & ExtendedWindowStyleFlags.WS_EX_TOOLWINDOW) != 0) { + continue; + } + if (!window.Visible && !window.Iconic) { + continue; + } + windows.Add(window); + } + return windows; + } + /// /// Find a window belonging to the same process as the supplied window. ///