2013-11-03 23:53:49 +13:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
2014-05-13 21:06:40 +12:00
|
|
|
|
Copyright (C) 2007-2014 ShareX Developers
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
using HelpersLib;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
2013-11-16 22:11:39 +13:00
|
|
|
|
namespace ScreenCaptureLib
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-09-13 19:36:16 +12:00
|
|
|
|
public class WindowsRectangleList
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-08-07 14:22:45 +12:00
|
|
|
|
public IntPtr IgnoreHandle { get; set; }
|
2013-11-03 23:53:49 +13:00
|
|
|
|
public bool IncludeChildWindows { get; set; }
|
|
|
|
|
|
2014-09-13 18:50:17 +12:00
|
|
|
|
private List<Rectangle> rectangles;
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2014-09-13 18:50:17 +12:00
|
|
|
|
public List<Rectangle> GetWindowsRectangleList()
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-09-13 18:50:17 +12:00
|
|
|
|
rectangles = new List<Rectangle>();
|
2013-11-03 23:53:49 +13:00
|
|
|
|
NativeMethods.EnumWindowsProc ewp = EvalWindow;
|
|
|
|
|
NativeMethods.EnumWindows(ewp, IntPtr.Zero);
|
|
|
|
|
|
|
|
|
|
List<Rectangle> result = new List<Rectangle>();
|
|
|
|
|
|
2014-09-13 18:50:17 +12:00
|
|
|
|
foreach (Rectangle rect in rectangles)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
bool rectVisible = true;
|
|
|
|
|
|
|
|
|
|
foreach (Rectangle rect2 in result)
|
|
|
|
|
{
|
|
|
|
|
if (rect2.Contains(rect))
|
|
|
|
|
{
|
|
|
|
|
rectVisible = false;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (rectVisible)
|
|
|
|
|
{
|
|
|
|
|
result.Add(rect);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-09-13 18:50:17 +12:00
|
|
|
|
private bool EvalWindow(IntPtr hWnd, IntPtr lParam)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-09-13 18:50:17 +12:00
|
|
|
|
return CheckHandle(hWnd, true);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-13 18:50:17 +12:00
|
|
|
|
private bool EvalControl(IntPtr hWnd, IntPtr lParam)
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
2014-09-13 18:50:17 +12:00
|
|
|
|
return CheckHandle(hWnd, false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool CheckHandle(IntPtr handle, bool isWindow)
|
|
|
|
|
{
|
|
|
|
|
if (handle == IgnoreHandle || !NativeMethods.IsWindowVisible(handle))
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
2014-09-13 18:50:17 +12:00
|
|
|
|
Rectangle rect;
|
|
|
|
|
|
|
|
|
|
if (isWindow)
|
|
|
|
|
{
|
|
|
|
|
rect = CaptureHelpers.GetWindowRectangle(handle);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
rect = NativeMethods.GetWindowRect(handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!rect.IsValid())
|
2013-11-03 23:53:49 +13:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (IncludeChildWindows)
|
|
|
|
|
{
|
2014-09-13 18:50:17 +12:00
|
|
|
|
NativeMethods.EnumWindowsProc ewp = EvalControl;
|
|
|
|
|
NativeMethods.EnumChildWindows(handle, ewp, IntPtr.Zero);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isWindow)
|
|
|
|
|
{
|
|
|
|
|
Rectangle clientRect = NativeMethods.GetClientRect(handle);
|
|
|
|
|
|
|
|
|
|
if (clientRect.IsValid())
|
|
|
|
|
{
|
|
|
|
|
rectangles.Add(clientRect);
|
|
|
|
|
}
|
2013-11-03 23:53:49 +13:00
|
|
|
|
}
|
|
|
|
|
|
2014-09-13 18:50:17 +12:00
|
|
|
|
rectangles.Add(rect);
|
2013-11-03 23:53:49 +13:00
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|