diff --git a/ShareX/Forms/InspectWindowForm.Designer.cs b/ShareX/Forms/InspectWindowForm.Designer.cs index c2196a212..f126205d8 100644 --- a/ShareX/Forms/InspectWindowForm.Designer.cs +++ b/ShareX/Forms/InspectWindowForm.Designer.cs @@ -29,13 +29,16 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(InspectWindowForm)); this.rtbInfo = new System.Windows.Forms.RichTextBox(); this.pInfo = new System.Windows.Forms.Panel(); this.btnInspectWindow = new System.Windows.Forms.Button(); this.btnInspectControl = 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.SuspendLayout(); // @@ -75,18 +78,32 @@ private void InitializeComponent() this.btnRefresh.UseVisualStyleBackColor = true; this.btnRefresh.Click += new System.EventHandler(this.btnRefresh_Click); // - // btnPinToTop + // cmsWindowList // - resources.ApplyResources(this.btnPinToTop, "btnPinToTop"); - this.btnPinToTop.Name = "btnPinToTop"; - this.btnPinToTop.UseVisualStyleBackColor = true; - this.btnPinToTop.Click += new System.EventHandler(this.btnPinToTop_Click); + this.cmsWindowList.Name = "cmsWindowList"; + resources.ApplyResources(this.cmsWindowList, "cmsWindowList"); + // + // 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 // resources.ApplyResources(this, "$this"); 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.btnInspectControl); this.Controls.Add(this.btnInspectWindow); @@ -94,6 +111,7 @@ private void InitializeComponent() this.Name = "InspectWindowForm"; this.pInfo.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 btnInspectControl; 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; } } \ No newline at end of file diff --git a/ShareX/Forms/InspectWindowForm.cs b/ShareX/Forms/InspectWindowForm.cs index 45db561e5..f9d1fcb7f 100644 --- a/ShareX/Forms/InspectWindowForm.cs +++ b/ShareX/Forms/InspectWindowForm.cs @@ -27,6 +27,9 @@ You should have received a copy of the GNU General Public License using ShareX.Properties; using ShareX.ScreenCaptureLib; using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; using System.Windows.Forms; namespace ShareX @@ -44,6 +47,54 @@ public InspectWindowForm() SelectHandle(true); } + private void UpdateWindowListMenu() + { + cmsWindowList.Items.Clear(); + + WindowsList windowsList = new WindowsList(); + List windows = windowsList.GetVisibleWindowsList(); + + if (windows != null && windows.Count > 0) + { + List items = new List(); + + 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) { RegionCaptureOptions options = new RegionCaptureOptions() @@ -57,18 +108,31 @@ private bool SelectHandle(bool isWindow) if (simpleWindowInfo != null) { - SelectedWindow = new WindowInfo(simpleWindowInfo.Handle); - IsWindow = isWindow; - UpdateWindowInfo(); + SelectWindow(simpleWindowInfo.Handle, isWindow); + return true; } + UpdateWindowInfo(); + return false; } 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(); 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) { SelectHandle(true); @@ -124,14 +193,15 @@ private void btnRefresh_Click(object sender, EventArgs e) 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); - windowInfo.TopMost = !windowInfo.TopMost; - - UpdateWindowInfo(); + UpdateWindowInfo(); + } } } } \ No newline at end of file diff --git a/ShareX/Forms/InspectWindowForm.resx b/ShareX/Forms/InspectWindowForm.resx index 640d7953e..2932bb249 100644 --- a/ShareX/Forms/InspectWindowForm.resx +++ b/ShareX/Forms/InspectWindowForm.resx @@ -126,15 +126,21 @@ Arial, 11.25pt - 3, 3 + 4, 4 + + + 4, 4, 4, 4 - 664, 480 + 686, 630 0 + + + rtbInfo @@ -151,16 +157,19 @@ Top, Bottom, Left, Right - 8, 40 + 208, 8 + + + 4, 4, 4, 4 - 3, 3, 3, 3 + 4, 4, 4, 4 - 672, 488 + 696, 640 - 4 + 5 pInfo @@ -172,16 +181,22 @@ $this - 4 + 6 + + + NoControl - 8, 8 + 8, 48 + + + 4, 4, 4, 4 - 144, 24 + 192, 32 - 0 + 1 Inspect window... @@ -196,16 +211,22 @@ $this - 3 + 5 + + + NoControl - 160, 8 + 8, 88 + + + 4, 4, 4, 4 - 144, 24 + 192, 32 - 1 + 2 Inspect control... @@ -220,16 +241,22 @@ $this - 2 + 4 + + + NoControl - 312, 8 + 8, 128 + + + 4, 4, 4, 4 - 144, 24 + 192, 32 - 2 + 3 Refresh @@ -244,43 +271,91 @@ $this - 1 - - - False - - - 464, 8 - - - 144, 24 - - 3 - - Pin to top + + 17, 17 + + + 61, 4 - - btnPinToTop + + cmsWindowList - - System.Windows.Forms.Button, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - + + NoControl + + + 8, 8 + + + 192, 32 + + + 0 + + + Select a window + + + mbWindowList + + + ShareX.HelpersLib.MenuButton, ShareX.HelpersLib, Version=15.0.1.0, Culture=neutral, PublicKeyToken=null + + $this - - 0 + + 2 + + + True + + + 9, 169 + + + 83, 20 + + + 4 + + + Top most + + + cbTopMost + + + System.Windows.Forms.CheckBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 1 True + + 53 + - 6, 13 + 8, 16 - 689, 536 + 913, 657 + + + Microsoft Sans Serif, 9.75pt + + + 4, 4, 4, 4 CenterScreen