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
|
2024-01-03 12:57:14 +13:00
|
|
|
|
Copyright (c) 2007-2024 ShareX Team
|
2021-01-14 08:16:43 +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 ShareX.HelpersLib;
|
2021-08-20 04:08:05 +12:00
|
|
|
|
using ShareX.Properties;
|
2021-01-14 08:16:43 +13:00
|
|
|
|
using ShareX.ScreenCaptureLib;
|
|
|
|
|
using System;
|
2023-12-18 20:30:20 +13:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
2021-01-14 08:16:43 +13:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
namespace ShareX
|
|
|
|
|
{
|
|
|
|
|
public partial class InspectWindowForm : Form
|
|
|
|
|
{
|
|
|
|
|
public WindowInfo SelectedWindow { get; private set; }
|
2022-03-05 22:26:51 +13:00
|
|
|
|
public bool IsWindow { get; private set; }
|
2021-01-14 08:16:43 +13:00
|
|
|
|
|
2023-12-20 15:25:31 +13:00
|
|
|
|
private bool updating;
|
|
|
|
|
|
2021-01-14 08:16:43 +13:00
|
|
|
|
public InspectWindowForm()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2021-01-14 08:48:41 +13:00
|
|
|
|
rtbInfo.AddContextMenu();
|
2023-06-04 10:07:30 +12:00
|
|
|
|
ShareXResources.ApplyTheme(this, true);
|
2022-03-05 22:26:51 +13:00
|
|
|
|
SelectHandle(true);
|
2021-01-14 08:16:43 +13:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-18 20:30:20 +13:00
|
|
|
|
private void UpdateWindowListMenu()
|
|
|
|
|
{
|
|
|
|
|
cmsWindowList.Items.Clear();
|
|
|
|
|
|
|
|
|
|
WindowsList windowsList = new WindowsList();
|
|
|
|
|
List<WindowInfo> windows = windowsList.GetVisibleWindowsList();
|
|
|
|
|
|
|
|
|
|
if (windows != null && windows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
List<ToolStripMenuItem> items = new List<ToolStripMenuItem>();
|
|
|
|
|
|
|
|
|
|
foreach (WindowInfo window in windows)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string title = window.Text;
|
|
|
|
|
string shortTitle = title.Truncate(50, "...");
|
|
|
|
|
ToolStripMenuItem tsmi = new ToolStripMenuItem(shortTitle);
|
|
|
|
|
tsmi.Click += (sender, e) => SelectWindow(window.Handle, true);
|
|
|
|
|
|
|
|
|
|
using (Icon icon = window.Icon)
|
|
|
|
|
{
|
|
|
|
|
if (icon != null && icon.Width > 0 && icon.Height > 0)
|
|
|
|
|
{
|
|
|
|
|
tsmi.Image = icon.ToBitmap();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
items.Add(tsmi);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
DebugHelper.WriteException(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cmsWindowList.Items.AddRange(items.OrderBy(x => x.Text).ToArray());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SelectWindow(IntPtr handle, bool isWindow)
|
|
|
|
|
{
|
|
|
|
|
SelectedWindow = new WindowInfo(handle);
|
|
|
|
|
IsWindow = isWindow;
|
|
|
|
|
|
|
|
|
|
UpdateWindowInfo();
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-05 22:26:51 +13:00
|
|
|
|
private bool SelectHandle(bool isWindow)
|
2021-01-14 08:16:43 +13:00
|
|
|
|
{
|
2022-03-05 22:26:51 +13:00
|
|
|
|
RegionCaptureOptions options = new RegionCaptureOptions()
|
|
|
|
|
{
|
|
|
|
|
DetectControls = !isWindow
|
|
|
|
|
};
|
2021-01-14 08:16:43 +13:00
|
|
|
|
|
|
|
|
|
SelectedWindow = null;
|
|
|
|
|
|
|
|
|
|
SimpleWindowInfo simpleWindowInfo = RegionCaptureTasks.GetWindowInfo(options);
|
|
|
|
|
|
|
|
|
|
if (simpleWindowInfo != null)
|
|
|
|
|
{
|
2023-12-18 20:30:20 +13:00
|
|
|
|
SelectWindow(simpleWindowInfo.Handle, isWindow);
|
|
|
|
|
|
2021-01-14 08:16:43 +13:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-18 20:30:20 +13:00
|
|
|
|
UpdateWindowInfo();
|
|
|
|
|
|
2021-01-14 08:16:43 +13:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateWindowInfo()
|
|
|
|
|
{
|
2023-12-20 15:25:31 +13:00
|
|
|
|
updating = true;
|
|
|
|
|
|
2023-12-18 20:30:20 +13:00
|
|
|
|
btnRefresh.Enabled = SelectedWindow != null;
|
|
|
|
|
|
|
|
|
|
if (SelectedWindow != null && IsWindow)
|
|
|
|
|
{
|
2023-12-20 15:25:31 +13:00
|
|
|
|
cbTopMost.Visible = true;
|
2023-12-18 20:30:20 +13:00
|
|
|
|
cbTopMost.Checked = SelectedWindow.TopMost;
|
2023-12-20 15:25:31 +13:00
|
|
|
|
|
|
|
|
|
nudOpacity.Visible = true;
|
|
|
|
|
nudOpacity.SetValue((int)Math.Round(SelectedWindow.Opacity / 255.0 * 100));
|
|
|
|
|
lblOpacity.Visible = true;
|
|
|
|
|
lblOpacityTip.Visible = true;
|
2023-12-18 20:30:20 +13:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-12-20 15:25:31 +13:00
|
|
|
|
cbTopMost.Visible = false;
|
|
|
|
|
nudOpacity.Visible = false;
|
|
|
|
|
lblOpacity.Visible = false;
|
|
|
|
|
lblOpacityTip.Visible = false;
|
2023-12-18 20:30:20 +13:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-14 08:16:43 +13:00
|
|
|
|
rtbInfo.ResetText();
|
|
|
|
|
|
|
|
|
|
if (SelectedWindow != null)
|
|
|
|
|
{
|
2021-01-14 10:46:08 +13:00
|
|
|
|
try
|
|
|
|
|
{
|
2021-08-20 04:08:05 +12:00
|
|
|
|
AddInfo(Resources.InspectWindow_WindowHandle, SelectedWindow.Handle.ToString("X8"));
|
|
|
|
|
AddInfo(Resources.InspectWindow_WindowTitle, SelectedWindow.Text);
|
|
|
|
|
AddInfo(Resources.InspectWindow_ClassName, SelectedWindow.ClassName);
|
|
|
|
|
AddInfo(Resources.InspectWindow_ProcessName, SelectedWindow.ProcessName);
|
|
|
|
|
AddInfo(Resources.InspectWindow_ProcessFileName, SelectedWindow.ProcessFileName);
|
|
|
|
|
AddInfo(Resources.InspectWindow_ProcessIdentifier, SelectedWindow.ProcessId.ToString());
|
|
|
|
|
AddInfo(Resources.InspectWindow_WindowRectangle, SelectedWindow.Rectangle.ToStringProper());
|
|
|
|
|
AddInfo(Resources.InspectWindow_ClientRectangle, SelectedWindow.ClientRectangle.ToStringProper());
|
2022-03-05 22:26:51 +13:00
|
|
|
|
AddInfo(Resources.InspectWindow_WindowStyles, SelectedWindow.Style.ToString().Replace(", ", "\r\n"));
|
2022-03-05 23:51:35 +13:00
|
|
|
|
AddInfo(Resources.InspectWindow_ExtendedWindowStyles, SelectedWindow.ExStyle.ToString().Replace(", ", "\r\n"));
|
2021-01-14 10:46:08 +13:00
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
2021-01-14 08:16:43 +13:00
|
|
|
|
}
|
2023-12-20 15:25:31 +13:00
|
|
|
|
|
|
|
|
|
updating = false;
|
2021-01-14 08:16:43 +13:00
|
|
|
|
}
|
2021-01-14 09:08:44 +13:00
|
|
|
|
|
|
|
|
|
private void AddInfo(string name, string value)
|
|
|
|
|
{
|
2021-01-17 05:24:55 +13:00
|
|
|
|
if (!string.IsNullOrEmpty(value))
|
|
|
|
|
{
|
2021-01-17 06:10:06 +13:00
|
|
|
|
if (rtbInfo.TextLength > 0)
|
|
|
|
|
{
|
|
|
|
|
rtbInfo.AppendLine();
|
|
|
|
|
rtbInfo.AppendLine();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-17 05:24:55 +13:00
|
|
|
|
rtbInfo.SetFontBold();
|
|
|
|
|
rtbInfo.AppendLine(name);
|
|
|
|
|
rtbInfo.SetFontRegular();
|
2021-01-17 06:10:06 +13:00
|
|
|
|
rtbInfo.AppendText(value);
|
2021-01-17 05:24:55 +13:00
|
|
|
|
}
|
2021-01-14 09:08:44 +13:00
|
|
|
|
}
|
2021-01-14 09:37:12 +13:00
|
|
|
|
|
2023-12-18 20:30:20 +13:00
|
|
|
|
private void mbWindowList_MouseDown(object sender, MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
UpdateWindowListMenu();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-14 09:37:12 +13:00
|
|
|
|
private void btnInspectWindow_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2022-03-05 22:26:51 +13:00
|
|
|
|
SelectHandle(true);
|
2021-01-14 09:37:12 +13:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void btnInspectControl_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
2022-03-05 22:26:51 +13:00
|
|
|
|
SelectHandle(false);
|
2021-01-14 09:37:12 +13:00
|
|
|
|
}
|
2021-01-14 10:46:08 +13:00
|
|
|
|
|
|
|
|
|
private void btnRefresh_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
UpdateWindowInfo();
|
|
|
|
|
}
|
2022-03-05 03:53:31 +13:00
|
|
|
|
|
2023-12-20 15:25:31 +13:00
|
|
|
|
private void cbTopMost_CheckedChanged(object sender, EventArgs e)
|
2022-03-05 03:53:31 +13:00
|
|
|
|
{
|
2023-12-20 15:25:31 +13:00
|
|
|
|
if (!updating && SelectedWindow != null)
|
2023-12-18 20:30:20 +13:00
|
|
|
|
{
|
2023-12-20 15:25:31 +13:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
WindowInfo windowInfo = new WindowInfo(SelectedWindow.Handle);
|
|
|
|
|
windowInfo.TopMost = cbTopMost.Checked;
|
2022-03-06 00:04:06 +13:00
|
|
|
|
|
2023-12-20 15:25:31 +13:00
|
|
|
|
UpdateWindowInfo();
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void nudOpacity_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (!updating && SelectedWindow != null)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
WindowInfo windowInfo = new WindowInfo(SelectedWindow.Handle);
|
|
|
|
|
windowInfo.Opacity = (byte)Math.Round(nudOpacity.Value / 100 * 255);
|
|
|
|
|
|
|
|
|
|
UpdateWindowInfo();
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
}
|
2023-12-18 20:30:20 +13:00
|
|
|
|
}
|
2022-03-05 03:53:31 +13:00
|
|
|
|
}
|
2021-01-14 08:16:43 +13:00
|
|
|
|
}
|
|
|
|
|
}
|