From 568264a0457b86b80d8b37e98dedd888fe42f167 Mon Sep 17 00:00:00 2001 From: RKrom Date: Fri, 5 Oct 2012 10:24:35 +0000 Subject: [PATCH] Small code optimization in GetActiveWindow, and bugfix in an unused method GetWindow (used for testing) git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2122 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- GreenshotPlugin/Core/WindowsHelper.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/GreenshotPlugin/Core/WindowsHelper.cs b/GreenshotPlugin/Core/WindowsHelper.cs index 92325f1e9..f1913c2ee 100644 --- a/GreenshotPlugin/Core/WindowsHelper.cs +++ b/GreenshotPlugin/Core/WindowsHelper.cs @@ -488,6 +488,9 @@ namespace GreenshotPlugin.Core { /// null if nothing found, otherwise the WindowDetails instance of the "child" public WindowDetails GetWindow(GetWindowCommand gwCommand) { IntPtr tmphWnd = User32.GetWindow(Handle, gwCommand); + if (IntPtr.Zero == tmphWnd) { + return null; + } WindowDetails windowDetails = new WindowDetails(tmphWnd); windowDetails.parent = this; return windowDetails; @@ -1389,9 +1392,13 @@ namespace GreenshotPlugin.Core { public static WindowDetails GetActiveWindow() { IntPtr hWnd = User32.GetForegroundWindow(); if (hWnd != null && hWnd != IntPtr.Zero) { + if (ignoreHandles.Contains(hWnd)) { + return WindowDetails.GetDesktopWindow(); + } + WindowDetails activeWindow = new WindowDetails(hWnd); // Invisible Windows should not be active - if (!activeWindow.Visible || ignoreHandles.Contains(activeWindow.Handle)) { + if (!activeWindow.Visible) { return WindowDetails.GetDesktopWindow(); } return activeWindow;