Fix for bug #3579138, minimized windows can't be captured via the context menu.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2205 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-10-26 15:27:48 +00:00
parent 5723f6fa5d
commit 4d41fc0a43
2 changed files with 44 additions and 10 deletions

View file

@ -316,8 +316,6 @@ namespace Greenshot {
public MainForm(CopyDataTransport dataTransport) { public MainForm(CopyDataTransport dataTransport) {
instance = this; instance = this;
// Make sure we never capture the mainform
WindowDetails.RegisterIgnoreHandle(this.Handle);
// //
// The InitializeComponent() call is required for Windows Forms designer support. // 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 // Setting it to true this late prevents Problems with the context menu
notifyIcon.Visible = !conf.HideTrayicon; 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(); // Create a new instance of the class: copyData = new CopyData();
copyData = new CopyData(); copyData = new CopyData();
@ -799,8 +800,8 @@ namespace Greenshot {
menuItem.DropDownItems.Clear(); menuItem.DropDownItems.Clear();
// check if thumbnailPreview is enabled and DWM is enabled // check if thumbnailPreview is enabled and DWM is enabled
bool thumbnailPreview = conf.ThumnailPreview && DWM.isDWMEnabled(); bool thumbnailPreview = conf.ThumnailPreview && DWM.isDWMEnabled();
List<WindowDetails> windows = WindowDetails.GetVisibleWindows(); List<WindowDetails> windows = WindowDetails.GetTopLevelWindows();
foreach(WindowDetails window in windows) { foreach(WindowDetails window in windows) {
ToolStripMenuItem captureWindowItem = new ToolStripMenuItem(window.Text); ToolStripMenuItem captureWindowItem = new ToolStripMenuItem(window.Text);
captureWindowItem.Tag = window; captureWindowItem.Tag = window;

View file

@ -579,7 +579,8 @@ namespace GreenshotPlugin.Core {
public bool HasParent { public bool HasParent {
get { get {
return !IntPtr.Zero.Equals(parentHandle); GetParent();
return parentHandle != IntPtr.Zero;
} }
} }
@ -1477,12 +1478,8 @@ namespace GreenshotPlugin.Core {
if (!window.Visible) { if (!window.Visible) {
continue; continue;
} }
// Ignore internal windows
if (ignoreHandles.Contains(window.Handle)) {
continue;
}
// Ignore some classes // Ignore some classes
List<string> ignoreClasses = new List<string>(new string[] {"Progman", "XLMAIN", "Button"}); //"MS-SDIa" List<string> ignoreClasses = new List<string>(new string[] { "Progman", "XLMAIN", "Button", "Dwm" }); //"MS-SDIa"
if (ignoreClasses.Contains(window.ClassName)) { if (ignoreClasses.Contains(window.ClassName)) {
continue; continue;
} }
@ -1497,6 +1494,42 @@ namespace GreenshotPlugin.Core {
return windows; return windows;
} }
/// <summary>
/// Get all the top level windows
/// </summary>
/// <returns>List<WindowDetails> with all the top level windows</returns>
public static List<WindowDetails> GetTopLevelWindows() {
List<WindowDetails> windows = new List<WindowDetails>();
Rectangle screenBounds = WindowCapture.GetScreenBounds();
List<WindowDetails> allWindows = WindowDetails.GetAllWindows();
foreach (WindowDetails window in allWindows) {
// Ignore windows without title
if (window.Text.Length == 0) {
continue;
}
// Ignore some classes
List<string> ignoreClasses = new List<string>(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;
}
/// <summary> /// <summary>
/// Find a window belonging to the same process as the supplied window. /// Find a window belonging to the same process as the supplied window.
/// </summary> /// </summary>