Added window list and "Top most" checkbox to "Inspect window" tool

This commit is contained in:
Jaex 2023-12-18 10:30:20 +03:00
parent 52a71c8b8d
commit ce6ce4d0cd
3 changed files with 224 additions and 59 deletions

View file

@ -29,13 +29,16 @@ protected override void Dispose(bool disposing)
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(InspectWindowForm)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(InspectWindowForm));
this.rtbInfo = new System.Windows.Forms.RichTextBox(); this.rtbInfo = new System.Windows.Forms.RichTextBox();
this.pInfo = new System.Windows.Forms.Panel(); this.pInfo = new System.Windows.Forms.Panel();
this.btnInspectWindow = new System.Windows.Forms.Button(); this.btnInspectWindow = new System.Windows.Forms.Button();
this.btnInspectControl = new System.Windows.Forms.Button(); this.btnInspectControl = new System.Windows.Forms.Button();
this.btnRefresh = new System.Windows.Forms.Button(); this.btnRefresh = new System.Windows.Forms.Button();
this.btnPinToTop = new System.Windows.Forms.Button(); this.cmsWindowList = new System.Windows.Forms.ContextMenuStrip(this.components);
this.mbWindowList = new ShareX.HelpersLib.MenuButton();
this.cbTopMost = new System.Windows.Forms.CheckBox();
this.pInfo.SuspendLayout(); this.pInfo.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
@ -75,18 +78,32 @@ private void InitializeComponent()
this.btnRefresh.UseVisualStyleBackColor = true; this.btnRefresh.UseVisualStyleBackColor = true;
this.btnRefresh.Click += new System.EventHandler(this.btnRefresh_Click); this.btnRefresh.Click += new System.EventHandler(this.btnRefresh_Click);
// //
// btnPinToTop // cmsWindowList
// //
resources.ApplyResources(this.btnPinToTop, "btnPinToTop"); this.cmsWindowList.Name = "cmsWindowList";
this.btnPinToTop.Name = "btnPinToTop"; resources.ApplyResources(this.cmsWindowList, "cmsWindowList");
this.btnPinToTop.UseVisualStyleBackColor = true; //
this.btnPinToTop.Click += new System.EventHandler(this.btnPinToTop_Click); // mbWindowList
//
resources.ApplyResources(this.mbWindowList, "mbWindowList");
this.mbWindowList.Menu = this.cmsWindowList;
this.mbWindowList.Name = "mbWindowList";
this.mbWindowList.UseVisualStyleBackColor = true;
this.mbWindowList.MouseDown += new System.Windows.Forms.MouseEventHandler(this.mbWindowList_MouseDown);
//
// cbTopMost
//
resources.ApplyResources(this.cbTopMost, "cbTopMost");
this.cbTopMost.Name = "cbTopMost";
this.cbTopMost.UseVisualStyleBackColor = true;
this.cbTopMost.Click += new System.EventHandler(this.cbTopMost_Click);
// //
// InspectWindowForm // InspectWindowForm
// //
resources.ApplyResources(this, "$this"); resources.ApplyResources(this, "$this");
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.btnPinToTop); this.Controls.Add(this.cbTopMost);
this.Controls.Add(this.mbWindowList);
this.Controls.Add(this.btnRefresh); this.Controls.Add(this.btnRefresh);
this.Controls.Add(this.btnInspectControl); this.Controls.Add(this.btnInspectControl);
this.Controls.Add(this.btnInspectWindow); this.Controls.Add(this.btnInspectWindow);
@ -94,6 +111,7 @@ private void InitializeComponent()
this.Name = "InspectWindowForm"; this.Name = "InspectWindowForm";
this.pInfo.ResumeLayout(false); this.pInfo.ResumeLayout(false);
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout();
} }
@ -104,6 +122,8 @@ private void InitializeComponent()
private System.Windows.Forms.Button btnInspectWindow; private System.Windows.Forms.Button btnInspectWindow;
private System.Windows.Forms.Button btnInspectControl; private System.Windows.Forms.Button btnInspectControl;
private System.Windows.Forms.Button btnRefresh; private System.Windows.Forms.Button btnRefresh;
private System.Windows.Forms.Button btnPinToTop; private HelpersLib.MenuButton mbWindowList;
private System.Windows.Forms.ContextMenuStrip cmsWindowList;
private System.Windows.Forms.CheckBox cbTopMost;
} }
} }

View file

@ -27,6 +27,9 @@ You should have received a copy of the GNU General Public License
using ShareX.Properties; using ShareX.Properties;
using ShareX.ScreenCaptureLib; using ShareX.ScreenCaptureLib;
using System; using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
namespace ShareX namespace ShareX
@ -44,6 +47,54 @@ public InspectWindowForm()
SelectHandle(true); SelectHandle(true);
} }
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();
}
private bool SelectHandle(bool isWindow) private bool SelectHandle(bool isWindow)
{ {
RegionCaptureOptions options = new RegionCaptureOptions() RegionCaptureOptions options = new RegionCaptureOptions()
@ -57,18 +108,31 @@ private bool SelectHandle(bool isWindow)
if (simpleWindowInfo != null) if (simpleWindowInfo != null)
{ {
SelectedWindow = new WindowInfo(simpleWindowInfo.Handle); SelectWindow(simpleWindowInfo.Handle, isWindow);
IsWindow = isWindow;
UpdateWindowInfo();
return true; return true;
} }
UpdateWindowInfo();
return false; return false;
} }
private void UpdateWindowInfo() private void UpdateWindowInfo()
{ {
btnPinToTop.Enabled = SelectedWindow != null && IsWindow; btnRefresh.Enabled = SelectedWindow != null;
if (SelectedWindow != null && IsWindow)
{
cbTopMost.Enabled = true;
cbTopMost.Checked = SelectedWindow.TopMost;
}
else
{
cbTopMost.Enabled = false;
cbTopMost.Checked = false;
}
rtbInfo.ResetText(); rtbInfo.ResetText();
if (SelectedWindow != null) if (SelectedWindow != null)
@ -109,6 +173,11 @@ private void AddInfo(string name, string value)
} }
} }
private void mbWindowList_MouseDown(object sender, MouseEventArgs e)
{
UpdateWindowListMenu();
}
private void btnInspectWindow_Click(object sender, EventArgs e) private void btnInspectWindow_Click(object sender, EventArgs e)
{ {
SelectHandle(true); SelectHandle(true);
@ -124,14 +193,15 @@ private void btnRefresh_Click(object sender, EventArgs e)
UpdateWindowInfo(); UpdateWindowInfo();
} }
private void btnPinToTop_Click(object sender, EventArgs e) private void cbTopMost_Click(object sender, EventArgs e)
{ {
if (SelectedWindow == null) return; if (SelectedWindow != null)
{
WindowInfo windowInfo = new WindowInfo(SelectedWindow.Handle);
windowInfo.TopMost = cbTopMost.Checked;
WindowInfo windowInfo = new WindowInfo(SelectedWindow.Handle); UpdateWindowInfo();
windowInfo.TopMost = !windowInfo.TopMost; }
UpdateWindowInfo();
} }
} }
} }

View file

@ -126,15 +126,21 @@
<value>Arial, 11.25pt</value> <value>Arial, 11.25pt</value>
</data> </data>
<data name="rtbInfo.Location" type="System.Drawing.Point, System.Drawing"> <data name="rtbInfo.Location" type="System.Drawing.Point, System.Drawing">
<value>3, 3</value> <value>4, 4</value>
</data>
<data name="rtbInfo.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
</data> </data>
<data name="rtbInfo.Size" type="System.Drawing.Size, System.Drawing"> <data name="rtbInfo.Size" type="System.Drawing.Size, System.Drawing">
<value>664, 480</value> <value>686, 630</value>
</data> </data>
<assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> <assembly alias="mscorlib" name="mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="rtbInfo.TabIndex" type="System.Int32, mscorlib"> <data name="rtbInfo.TabIndex" type="System.Int32, mscorlib">
<value>0</value> <value>0</value>
</data> </data>
<data name="rtbInfo.Text" xml:space="preserve">
<value />
</data>
<data name="&gt;&gt;rtbInfo.Name" xml:space="preserve"> <data name="&gt;&gt;rtbInfo.Name" xml:space="preserve">
<value>rtbInfo</value> <value>rtbInfo</value>
</data> </data>
@ -151,16 +157,19 @@
<value>Top, Bottom, Left, Right</value> <value>Top, Bottom, Left, Right</value>
</data> </data>
<data name="pInfo.Location" type="System.Drawing.Point, System.Drawing"> <data name="pInfo.Location" type="System.Drawing.Point, System.Drawing">
<value>8, 40</value> <value>208, 8</value>
</data>
<data name="pInfo.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
</data> </data>
<data name="pInfo.Padding" type="System.Windows.Forms.Padding, System.Windows.Forms"> <data name="pInfo.Padding" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>3, 3, 3, 3</value> <value>4, 4, 4, 4</value>
</data> </data>
<data name="pInfo.Size" type="System.Drawing.Size, System.Drawing"> <data name="pInfo.Size" type="System.Drawing.Size, System.Drawing">
<value>672, 488</value> <value>696, 640</value>
</data> </data>
<data name="pInfo.TabIndex" type="System.Int32, mscorlib"> <data name="pInfo.TabIndex" type="System.Int32, mscorlib">
<value>4</value> <value>5</value>
</data> </data>
<data name="&gt;&gt;pInfo.Name" xml:space="preserve"> <data name="&gt;&gt;pInfo.Name" xml:space="preserve">
<value>pInfo</value> <value>pInfo</value>
@ -172,16 +181,22 @@
<value>$this</value> <value>$this</value>
</data> </data>
<data name="&gt;&gt;pInfo.ZOrder" xml:space="preserve"> <data name="&gt;&gt;pInfo.ZOrder" xml:space="preserve">
<value>4</value> <value>6</value>
</data>
<data name="btnInspectWindow.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data> </data>
<data name="btnInspectWindow.Location" type="System.Drawing.Point, System.Drawing"> <data name="btnInspectWindow.Location" type="System.Drawing.Point, System.Drawing">
<value>8, 8</value> <value>8, 48</value>
</data>
<data name="btnInspectWindow.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
</data> </data>
<data name="btnInspectWindow.Size" type="System.Drawing.Size, System.Drawing"> <data name="btnInspectWindow.Size" type="System.Drawing.Size, System.Drawing">
<value>144, 24</value> <value>192, 32</value>
</data> </data>
<data name="btnInspectWindow.TabIndex" type="System.Int32, mscorlib"> <data name="btnInspectWindow.TabIndex" type="System.Int32, mscorlib">
<value>0</value> <value>1</value>
</data> </data>
<data name="btnInspectWindow.Text" xml:space="preserve"> <data name="btnInspectWindow.Text" xml:space="preserve">
<value>Inspect window...</value> <value>Inspect window...</value>
@ -196,16 +211,22 @@
<value>$this</value> <value>$this</value>
</data> </data>
<data name="&gt;&gt;btnInspectWindow.ZOrder" xml:space="preserve"> <data name="&gt;&gt;btnInspectWindow.ZOrder" xml:space="preserve">
<value>3</value> <value>5</value>
</data>
<data name="btnInspectControl.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data> </data>
<data name="btnInspectControl.Location" type="System.Drawing.Point, System.Drawing"> <data name="btnInspectControl.Location" type="System.Drawing.Point, System.Drawing">
<value>160, 8</value> <value>8, 88</value>
</data>
<data name="btnInspectControl.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
</data> </data>
<data name="btnInspectControl.Size" type="System.Drawing.Size, System.Drawing"> <data name="btnInspectControl.Size" type="System.Drawing.Size, System.Drawing">
<value>144, 24</value> <value>192, 32</value>
</data> </data>
<data name="btnInspectControl.TabIndex" type="System.Int32, mscorlib"> <data name="btnInspectControl.TabIndex" type="System.Int32, mscorlib">
<value>1</value> <value>2</value>
</data> </data>
<data name="btnInspectControl.Text" xml:space="preserve"> <data name="btnInspectControl.Text" xml:space="preserve">
<value>Inspect control...</value> <value>Inspect control...</value>
@ -220,16 +241,22 @@
<value>$this</value> <value>$this</value>
</data> </data>
<data name="&gt;&gt;btnInspectControl.ZOrder" xml:space="preserve"> <data name="&gt;&gt;btnInspectControl.ZOrder" xml:space="preserve">
<value>2</value> <value>4</value>
</data>
<data name="btnRefresh.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data> </data>
<data name="btnRefresh.Location" type="System.Drawing.Point, System.Drawing"> <data name="btnRefresh.Location" type="System.Drawing.Point, System.Drawing">
<value>312, 8</value> <value>8, 128</value>
</data>
<data name="btnRefresh.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
</data> </data>
<data name="btnRefresh.Size" type="System.Drawing.Size, System.Drawing"> <data name="btnRefresh.Size" type="System.Drawing.Size, System.Drawing">
<value>144, 24</value> <value>192, 32</value>
</data> </data>
<data name="btnRefresh.TabIndex" type="System.Int32, mscorlib"> <data name="btnRefresh.TabIndex" type="System.Int32, mscorlib">
<value>2</value> <value>3</value>
</data> </data>
<data name="btnRefresh.Text" xml:space="preserve"> <data name="btnRefresh.Text" xml:space="preserve">
<value>Refresh</value> <value>Refresh</value>
@ -244,43 +271,91 @@
<value>$this</value> <value>$this</value>
</data> </data>
<data name="&gt;&gt;btnRefresh.ZOrder" xml:space="preserve"> <data name="&gt;&gt;btnRefresh.ZOrder" xml:space="preserve">
<value>1</value>
</data>
<data name="btnPinToTop.Enabled" type="System.Boolean, mscorlib">
<value>False</value>
</data>
<data name="btnPinToTop.Location" type="System.Drawing.Point, System.Drawing">
<value>464, 8</value>
</data>
<data name="btnPinToTop.Size" type="System.Drawing.Size, System.Drawing">
<value>144, 24</value>
</data>
<data name="btnPinToTop.TabIndex" type="System.Int32, mscorlib">
<value>3</value> <value>3</value>
</data> </data>
<data name="btnPinToTop.Text" xml:space="preserve"> <metadata name="cmsWindowList.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>Pin to top</value> <value>17, 17</value>
</metadata>
<data name="cmsWindowList.Size" type="System.Drawing.Size, System.Drawing">
<value>61, 4</value>
</data> </data>
<data name="&gt;&gt;btnPinToTop.Name" xml:space="preserve"> <data name="&gt;&gt;cmsWindowList.Name" xml:space="preserve">
<value>btnPinToTop</value> <value>cmsWindowList</value>
</data> </data>
<data name="&gt;&gt;btnPinToTop.Type" xml:space="preserve"> <data name="&gt;&gt;cmsWindowList.Type" xml:space="preserve">
<value>System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data> </data>
<data name="&gt;&gt;btnPinToTop.Parent" xml:space="preserve"> <data name="mbWindowList.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="mbWindowList.Location" type="System.Drawing.Point, System.Drawing">
<value>8, 8</value>
</data>
<data name="mbWindowList.Size" type="System.Drawing.Size, System.Drawing">
<value>192, 32</value>
</data>
<data name="mbWindowList.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
</data>
<data name="mbWindowList.Text" xml:space="preserve">
<value>Select a window</value>
</data>
<data name="&gt;&gt;mbWindowList.Name" xml:space="preserve">
<value>mbWindowList</value>
</data>
<data name="&gt;&gt;mbWindowList.Type" xml:space="preserve">
<value>ShareX.HelpersLib.MenuButton, ShareX.HelpersLib, Version=15.0.1.0, Culture=neutral, PublicKeyToken=null</value>
</data>
<data name="&gt;&gt;mbWindowList.Parent" xml:space="preserve">
<value>$this</value> <value>$this</value>
</data> </data>
<data name="&gt;&gt;btnPinToTop.ZOrder" xml:space="preserve"> <data name="&gt;&gt;mbWindowList.ZOrder" xml:space="preserve">
<value>0</value> <value>2</value>
</data>
<data name="cbTopMost.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="cbTopMost.Location" type="System.Drawing.Point, System.Drawing">
<value>9, 169</value>
</data>
<data name="cbTopMost.Size" type="System.Drawing.Size, System.Drawing">
<value>83, 20</value>
</data>
<data name="cbTopMost.TabIndex" type="System.Int32, mscorlib">
<value>4</value>
</data>
<data name="cbTopMost.Text" xml:space="preserve">
<value>Top most</value>
</data>
<data name="&gt;&gt;cbTopMost.Name" xml:space="preserve">
<value>cbTopMost</value>
</data>
<data name="&gt;&gt;cbTopMost.Type" xml:space="preserve">
<value>System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;cbTopMost.Parent" xml:space="preserve">
<value>$this</value>
</data>
<data name="&gt;&gt;cbTopMost.ZOrder" xml:space="preserve">
<value>1</value>
</data> </data>
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"> <metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value> <value>True</value>
</metadata> </metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>53</value>
</metadata>
<data name="$this.AutoScaleDimensions" type="System.Drawing.SizeF, System.Drawing"> <data name="$this.AutoScaleDimensions" type="System.Drawing.SizeF, System.Drawing">
<value>6, 13</value> <value>8, 16</value>
</data> </data>
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing"> <data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
<value>689, 536</value> <value>913, 657</value>
</data>
<data name="$this.Font" type="System.Drawing.Font, System.Drawing">
<value>Microsoft Sans Serif, 9.75pt</value>
</data>
<data name="$this.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>4, 4, 4, 4</value>
</data> </data>
<data name="$this.StartPosition" type="System.Windows.Forms.FormStartPosition, System.Windows.Forms"> <data name="$this.StartPosition" type="System.Windows.Forms.FormStartPosition, System.Windows.Forms">
<value>CenterScreen</value> <value>CenterScreen</value>