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
This commit is contained in:
RKrom 2012-10-05 10:24:35 +00:00
parent 21d273a8c3
commit 568264a045

View file

@ -488,6 +488,9 @@ namespace GreenshotPlugin.Core {
/// <returns>null if nothing found, otherwise the WindowDetails instance of the "child"</returns>
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;