ShareX/ShareX/Forms/InspectWindowForm.cs

106 lines
3.3 KiB
C#
Raw Normal View History

2021-01-14 08:16:43 +13:00
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (c) 2007-2020 ShareX Team
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 ShareX.HelpersLib;
using ShareX.ScreenCaptureLib;
using System;
using System.Windows.Forms;
namespace ShareX
{
public partial class InspectWindowForm : Form
{
public WindowInfo SelectedWindow { get; private set; }
public InspectWindowForm()
{
InitializeComponent();
2021-01-14 08:48:41 +13:00
rtbInfo.AddContextMenu();
ShareXResources.ApplyTheme(this);
2021-01-14 08:16:43 +13:00
SelectHandle();
}
private bool SelectHandle()
{
return SelectHandle(new RegionCaptureOptions());
}
private bool SelectHandle(RegionCaptureOptions options)
{
SelectedWindow = null;
SimpleWindowInfo simpleWindowInfo = RegionCaptureTasks.GetWindowInfo(options);
if (simpleWindowInfo != null)
{
SelectedWindow = new WindowInfo(simpleWindowInfo.Handle);
UpdateWindowInfo();
return true;
}
return false;
}
private void UpdateWindowInfo()
{
rtbInfo.ResetText();
if (SelectedWindow != null)
{
2021-01-14 09:08:44 +13:00
AddInfo("Window handle", SelectedWindow.Handle.ToString("X8"));
AddInfo("Window title", SelectedWindow.Text);
AddInfo("Class name", SelectedWindow.ClassName);
AddInfo("Process name", SelectedWindow.ProcessName);
AddInfo("Window rectangle", SelectedWindow.Rectangle.ToString());
AddInfo("Client rectangle", SelectedWindow.ClientRectangle.ToString());
AddInfo("Window styles", SelectedWindow.Styles.ToString());
2021-01-14 08:16:43 +13:00
}
}
2021-01-14 09:08:44 +13:00
private void AddInfo(string name, string value)
{
rtbInfo.SetFontBold();
rtbInfo.AppendLine(name + ":");
rtbInfo.SetFontRegular();
rtbInfo.AppendLine(value);
rtbInfo.AppendLine();
}
private void btnInspectWindow_Click(object sender, EventArgs e)
{
RegionCaptureOptions options = new RegionCaptureOptions()
{
DetectControls = false
};
SelectHandle(options);
}
private void btnInspectControl_Click(object sender, EventArgs e)
{
SelectHandle();
}
2021-01-14 08:16:43 +13:00
}
}