From 46bfdfe49e4390c51fbfc22a8f602c2a475b45d9 Mon Sep 17 00:00:00 2001 From: CreepyCrafter24 <33260128+CreepyCrafter24@users.noreply.github.com> Date: Sat, 4 Apr 2020 12:05:42 +0200 Subject: [PATCH] Improved window finding --- Misc/DataGridViewNumericUpDownCell.cs | 3 +- Misc/Misc.csproj | 3 - W32.Test/App.config | 6 - W32.Test/MainForm.Designer.cs | 20 +-- W32.Test/MainForm.cs | 195 ++++++++++++---------- W32.Test/Properties/AssemblyInfo.cs | 35 ---- W32.Test/Properties/Resources.Designer.cs | 63 ------- W32.Test/Properties/Resources.resx | 117 ------------- W32.Test/Properties/Settings.Designer.cs | 26 --- W32.Test/Properties/Settings.settings | 7 - W32.Test/W32.Test.csproj | 6 +- W32/DeskMan.cs | 4 +- W32/Hooks/MouseHookEventArgs.cs | 2 +- W32/W32.csproj | 3 - W32/Wnd32.cs | 14 +- 15 files changed, 133 insertions(+), 371 deletions(-) delete mode 100644 W32.Test/App.config delete mode 100644 W32.Test/Properties/AssemblyInfo.cs delete mode 100644 W32.Test/Properties/Resources.Designer.cs delete mode 100644 W32.Test/Properties/Resources.resx delete mode 100644 W32.Test/Properties/Settings.Designer.cs delete mode 100644 W32.Test/Properties/Settings.settings diff --git a/Misc/DataGridViewNumericUpDownCell.cs b/Misc/DataGridViewNumericUpDownCell.cs index 90af4b7..28f08cf 100644 --- a/Misc/DataGridViewNumericUpDownCell.cs +++ b/Misc/DataGridViewNumericUpDownCell.cs @@ -662,8 +662,7 @@ namespace CC_Functions.Misc /// Returns a standard textual representation of the cell. /// public override string ToString() => - "DataGridViewNumericUpDownCell { ColumnIndex=" + ColumnIndex.ToString(CultureInfo.CurrentCulture) + - ", RowIndex=" + RowIndex.ToString(CultureInfo.CurrentCulture) + " }"; + $"DataGridViewNumericUpDownCell {{ ColumnIndex={ColumnIndex.ToString(CultureInfo.CurrentCulture)}, RowIndex={RowIndex.ToString(CultureInfo.CurrentCulture)} }}"; /// /// Little utility function used by both the cell and column types to translate a DataGridViewContentAlignment value diff --git a/Misc/Misc.csproj b/Misc/Misc.csproj index 58e89c3..ee313e6 100644 --- a/Misc/Misc.csproj +++ b/Misc/Misc.csproj @@ -4,12 +4,9 @@ CC_Functions.Misc CC_Functions.Misc 8 - enable - false true net461;netcoreapp3.1 false - CC-Functions.Misc CC-Functions.Misc CC24 diff --git a/W32.Test/App.config b/W32.Test/App.config deleted file mode 100644 index 51847c7..0000000 --- a/W32.Test/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/W32.Test/MainForm.Designer.cs b/W32.Test/MainForm.Designer.cs index 3a96f19..73b368c 100644 --- a/W32.Test/MainForm.Designer.cs +++ b/W32.Test/MainForm.Designer.cs @@ -59,7 +59,7 @@ this.wnd_action_title_get = new System.Windows.Forms.Button(); this.wnd_action_title_set = new System.Windows.Forms.Button(); this.wnd_select_title_box = new System.Windows.Forms.TextBox(); - this.wnd_selet_class_button = new System.Windows.Forms.Button(); + this.wnd_select_class_button = new System.Windows.Forms.Button(); this.wnd_select_title_button = new System.Windows.Forms.Button(); this.wnd_select_selected = new System.Windows.Forms.Label(); this.wnd_select_self = new System.Windows.Forms.Button(); @@ -444,13 +444,13 @@ // // wnd_selet_class_button // - this.wnd_selet_class_button.Location = new System.Drawing.Point(7, 89); - this.wnd_selet_class_button.Name = "wnd_selet_class_button"; - this.wnd_selet_class_button.Size = new System.Drawing.Size(94, 27); - this.wnd_selet_class_button.TabIndex = 4; - this.wnd_selet_class_button.Text = "Select (class):"; - this.wnd_selet_class_button.UseVisualStyleBackColor = true; - this.wnd_selet_class_button.Click += new System.EventHandler(this.Wnd_selet_class_button_Click); + this.wnd_select_class_button.Location = new System.Drawing.Point(7, 89); + this.wnd_select_class_button.Name = "wnd_select_class_button"; + this.wnd_select_class_button.Size = new System.Drawing.Size(94, 27); + this.wnd_select_class_button.TabIndex = 4; + this.wnd_select_class_button.Text = "Select (class):"; + this.wnd_select_class_button.UseVisualStyleBackColor = true; + this.wnd_select_class_button.Click += new System.EventHandler(this.Wnd_select_class_button_Click); // // wnd_select_title_button // @@ -505,7 +505,7 @@ this.wnd.Controls.Add(this.wnd_action_title_set); this.wnd.Controls.Add(this.wnd_select_title_box); this.wnd.Controls.Add(this.wnd_select_class_box); - this.wnd.Controls.Add(this.wnd_selet_class_button); + this.wnd.Controls.Add(this.wnd_select_class_button); this.wnd.Controls.Add(this.wnd_select_title_button); this.wnd.Controls.Add(this.wnd_select_selected); this.wnd.Controls.Add(this.wnd_select_self); @@ -825,7 +825,7 @@ private System.Windows.Forms.Button wnd_action_title_get; private System.Windows.Forms.Button wnd_action_title_set; private System.Windows.Forms.TextBox wnd_select_title_box; - private System.Windows.Forms.Button wnd_selet_class_button; + private System.Windows.Forms.Button wnd_select_class_button; private System.Windows.Forms.Button wnd_select_title_button; private System.Windows.Forms.Label wnd_select_selected; private System.Windows.Forms.Button wnd_select_self; diff --git a/W32.Test/MainForm.cs b/W32.Test/MainForm.cs index eb75660..516e0f0 100644 --- a/W32.Test/MainForm.cs +++ b/W32.Test/MainForm.cs @@ -11,34 +11,33 @@ namespace CC_Functions.W32.Test { public partial class MainForm : Form { - private static Wnd32 tmpWnd32_obj; - private static MainForm mainF; - private static Form frm; - private static Label lab; - private readonly KeyboardHook kHook; - private readonly MouseHook mHook; - private readonly Label[] readerLabels; + private static Wnd32 _tmpWnd32Obj; + private static MainForm _mainF; + private readonly KeyboardHook _kHook; + private readonly MouseHook _mHook; + private readonly Label[] _readerLabels; public MainForm() { + _wndSelectMouseCurrent = this.GetWnd32(); InitializeComponent(); - mainF = this; - tmpWnd32_obj = Wnd32.FromForm(this); + _mainF = this; + _tmpWnd32Obj = Wnd32.FromForm(this); #if DEBUG tmpWnd32_obj.MakeOverlay(); #endif set_up_box(power_mode_box, typeof(ShutdownMode)); set_up_box(power_reason_box, typeof(ShutdownReason)); set_up_box(power_mod_box, typeof(ShutdownMod)); - mHook = new MouseHook(); - kHook = new KeyboardHook(); + _mHook = new MouseHook(); + _kHook = new KeyboardHook(); wnd_action_pos_x_bar.Maximum = Screen.PrimaryScreen.Bounds.Width; wnd_action_pos_y_bar.Maximum = Screen.PrimaryScreen.Bounds.Height; wnd_action_pos_w_bar.Maximum = Screen.PrimaryScreen.Bounds.Width; wnd_action_pos_h_bar.Maximum = Screen.PrimaryScreen.Bounds.Height; wnd_action_style.DataSource = Enum.GetValues(typeof(FormWindowState)); - wnd_action_style.SelectedItem = tmpWnd32_obj.State; - readerLabels = Enum.GetValues(typeof(Keys)).OfType().OrderBy(s => s.ToString()).Select(s => + wnd_action_style.SelectedItem = _tmpWnd32Obj.State; + _readerLabels = Enum.GetValues(typeof(Keys)).OfType().OrderBy(s => s.ToString()).Select(s => { Label lab = new Label {Tag = s}; readerFlow.Controls.Add(lab); @@ -50,17 +49,17 @@ namespace CC_Functions.W32.Test time_select.Value = DateTime.Now; } - private Wnd32 tmpWnd + private Wnd32 TmpWnd { - get => tmpWnd32_obj; + get => _tmpWnd32Obj; set { - tmpWnd32_obj = value; + _tmpWnd32Obj = value; Wnd_action_title_get_Click(null, null); } } - public void set_up_box(ComboBox box, Type enumT) + private static void set_up_box(ComboBox box, Type enumT) { box.DataSource = Enum.GetNames(enumT); Array tmp = Enum.GetValues(enumT); @@ -73,38 +72,38 @@ namespace CC_Functions.W32.Test } } - public object get_box_value(ComboBox box) => ((object[]) box.Tag)[box.SelectedIndex]; + private static object get_box_value(ListControl box) => ((object[]) box.Tag)[box.SelectedIndex]; private void Power_execute_Click(object sender, EventArgs e) => RaiseEvent( (ShutdownMode) get_box_value(power_mode_box), (ShutdownReason) get_box_value(power_reason_box), (ShutdownMod) get_box_value(power_mod_box)); - private void Wnd_select_self_Click(object sender, EventArgs e) => tmpWnd = Wnd32.FromForm(this); + private void Wnd_select_self_Click(object sender, EventArgs e) => TmpWnd = Wnd32.FromForm(this); private void wnd_select_list_Click(object sender, EventArgs e) => - tmpWnd = SelectBox.Show(Wnd32.Visible, "Please select a window") ?? tmpWnd; + TmpWnd = SelectBox.Show(Wnd32.Visible, "Please select a window") ?? TmpWnd; private void Wnd_select_title_button_Click(object sender, EventArgs e) => - tmpWnd = Wnd32.FromMetadata(null, wnd_select_title_box.Text); + TmpWnd = Wnd32.FromMetadata(null, wnd_select_title_box.Text); - private void Wnd_selet_class_button_Click(object sender, EventArgs e) => - tmpWnd = Wnd32.FromMetadata(wnd_select_class_box.Text); + private void Wnd_select_class_button_Click(object sender, EventArgs e) => + TmpWnd = Wnd32.FromMetadata(wnd_select_class_box.Text); - private void Wnd_action_title_set_Click(object sender, EventArgs e) => tmpWnd.Title = wnd_select_title_box.Text; + private void Wnd_action_title_set_Click(object sender, EventArgs e) => TmpWnd.Title = wnd_select_title_box.Text; private void Wnd_action_title_get_Click(object sender, EventArgs e) { - if (!tmpWnd.StillExists) - tmpWnd = Wnd32.FromForm(this); - wnd_select_title_box.Text = tmpWnd.Title; - wnd_action_enabled.Checked = tmpWnd.Enabled; - wnd_select_selected.Text = "Selected: " + tmpWnd.HWnd; - wnd_action_style.SelectedIndex = (int) tmpWnd.State; - wnd_select_class_box.Text = tmpWnd.ClassName; - wnd_action_visible.Checked = tmpWnd.Shown; + if (!TmpWnd.StillExists) + TmpWnd = Wnd32.FromForm(this); + wnd_select_title_box.Text = TmpWnd.Title; + wnd_action_enabled.Checked = TmpWnd.Enabled; + wnd_select_selected.Text = $"Selected: {TmpWnd.HWnd}"; + wnd_action_style.SelectedIndex = (int) TmpWnd.State; + wnd_select_class_box.Text = TmpWnd.ClassName; + wnd_action_visible.Checked = TmpWnd.Shown; try { - wnd_action_icon.BackgroundImage = tmpWnd.Icon.ToBitmap(); + wnd_action_icon.BackgroundImage = TmpWnd.Icon.ToBitmap(); } catch { @@ -113,93 +112,112 @@ namespace CC_Functions.W32.Test try { - wnd_action_pos_x_bar.Value = tmpWnd.Position.X; + wnd_action_pos_x_bar.Value = TmpWnd.Position.X; } catch { + // ignored } try { - wnd_action_pos_y_bar.Value = tmpWnd.Position.Y; + wnd_action_pos_y_bar.Value = TmpWnd.Position.Y; } catch { + // ignored } try { - wnd_action_pos_w_bar.Value = tmpWnd.Position.Width; + wnd_action_pos_w_bar.Value = TmpWnd.Position.Width; } catch { + // ignored } try { - wnd_action_pos_h_bar.Value = tmpWnd.Position.Height; + wnd_action_pos_h_bar.Value = TmpWnd.Position.Height; } catch { + // ignored } } private void Wnd_action_enabled_CheckedChanged(object sender, EventArgs e) => - tmpWnd.Enabled = wnd_action_enabled.Checked; + TmpWnd.Enabled = wnd_action_enabled.Checked; private void Wnd_action_visible_CheckedChanged(object sender, EventArgs e) => - tmpWnd.Shown = wnd_action_visible.Checked; + TmpWnd.Shown = wnd_action_visible.Checked; - private void Wnd_action_front_Click(object sender, EventArgs e) => tmpWnd.IsForeground = true; + private void Wnd_action_front_Click(object sender, EventArgs e) => TmpWnd.IsForeground = true; - private void Wnd_action_destroy_Click(object sender, EventArgs e) => tmpWnd.Destroy(); + private void Wnd_action_destroy_Click(object sender, EventArgs e) => TmpWnd.Destroy(); + private static Wnd32 _wndSelectMouseCurrent; private void Wnd_select_mouse_Click(object sender, EventArgs e) { WindowState = FormWindowState.Minimized; - tmpWnd = Wnd32.FromForm(this); - tmpWnd.Enabled = false; - frm = new Form(); - frm.BackColor = Color.White; - frm.Opacity = 0.4f; - frm.FormBorderStyle = FormBorderStyle.None; - frm.WindowState = FormWindowState.Maximized; - frm.Click += Frm_Click; - frm.MouseMove += Frm_MouseMove; - lab = new Label(); + TmpWnd = Wnd32.FromForm(this); + TmpWnd.Enabled = false; + Form frm = new Form + { + BackColor = Color.White, + Opacity = 0.4f, + FormBorderStyle = FormBorderStyle.None, + WindowState = FormWindowState.Maximized + }; + Label lab = new Label {AutoSize = true}; frm.Controls.Add(lab); + Panel pan = new Panel {BackColor = Color.Red}; + frm.Controls.Add(pan); + + void MouseEventHandler(object sender1, MouseEventArgs e1) + { + _wndSelectMouseCurrent = Wnd32.AllFromPoint(MousePosition, true).First(s => s != frm.GetWnd32()); + lab.Text = $"{_wndSelectMouseCurrent.Title} ({_wndSelectMouseCurrent.HWnd})"; + lab.Location = new Point(Cursor.Position.X + 5, Cursor.Position.Y + 5); + pan.Bounds = _wndSelectMouseCurrent.Position; + } + + void EventHandler(object sender1, EventArgs e1) + { + frm.Hide(); + frm.WindowState = FormWindowState.Minimized; + Wnd32 tmp = _wndSelectMouseCurrent; + TmpWnd.Enabled = true; + TmpWnd.IsForeground = true; + TmpWnd = tmp; + _mainF.WindowState = FormWindowState.Normal; + frm.Close(); + } + + frm.Click += EventHandler; + pan.Click += EventHandler; + lab.Click += EventHandler; + frm.MouseMove += MouseEventHandler; + pan.MouseMove += MouseEventHandler; + lab.MouseMove += MouseEventHandler; + frm.Show(); - Wnd32.FromForm(frm).Overlay = true; - } - - private void Frm_Click(object sender, EventArgs e) - { - frm.Hide(); - frm.WindowState = FormWindowState.Minimized; - Wnd32 tmp = Wnd32.FromPoint(MousePosition); - tmpWnd.Enabled = true; - tmpWnd.IsForeground = true; - tmpWnd = tmp; - mainF.WindowState = FormWindowState.Normal; - frm.Close(); - } - - private void Frm_MouseMove(object sender, MouseEventArgs e) - { - lab.Text = Wnd32.FromPoint(MousePosition).ToString(); - lab.Location = new Point(Cursor.Position.X + 5, Cursor.Position.Y + 5); + _wndSelectMouseCurrent = frm.GetWnd32(); + Cursor.Position = Cursor.Position; + frm.GetWnd32().Overlay = true; } private void Mouse_enabled_CheckedChanged(object sender, EventArgs e) { if (mouse_enabled.Checked) - mHook.OnMouse += MHook_OnMouse; + _mHook.OnMouse += MHook_OnMouse; else - mHook.OnMouse -= MHook_OnMouse; + _mHook.OnMouse -= MHook_OnMouse; } private void MHook_OnMouse(MouseHookEventArgs args) => - mouse_log.Text = args.Message + " -|- " + args.Point + "\r\n" + mouse_log.Text; + mouse_log.Text = $"{args.Message} -|- {args.Point}\r\n{mouse_log.Text}"; private void Mouse_log_TextChanged(object sender, EventArgs e) => mouse_log.Lines = mouse_log.Lines.Take(9).ToArray(); @@ -207,35 +225,34 @@ namespace CC_Functions.W32.Test private void Keyboard_enabled_CheckedChanged(object sender, EventArgs e) { if (keyboard_enabled.Checked) - kHook.OnKeyPress += KHook_OnKeyPress; + _kHook.OnKeyPress += KHook_OnKeyPress; else - kHook.OnKeyPress -= KHook_OnKeyPress; + _kHook.OnKeyPress -= KHook_OnKeyPress; } private void KHook_OnKeyPress(KeyboardHookEventArgs args) => - keyboard_log.Text = args.Key + "\r\n" + keyboard_log.Text; + keyboard_log.Text = $"{args.Key}\r\n{keyboard_log.Text}"; private void Keyboard_log_TextChanged(object sender, EventArgs e) => keyboard_log.Lines = keyboard_log.Lines.Take(8).ToArray(); private void Wnd_action_pos_Click(object sender, EventArgs e) => - tmpWnd.Position = new Rectangle(wnd_action_pos_x_bar.Value, wnd_action_pos_y_bar.Value, + TmpWnd.Position = new Rectangle(wnd_action_pos_x_bar.Value, wnd_action_pos_y_bar.Value, wnd_action_pos_w_bar.Value, wnd_action_pos_h_bar.Value); private void Wnd_action_style_SelectedIndexChanged(object sender, EventArgs e) { Enum.TryParse(wnd_action_style.SelectedValue.ToString(), out FormWindowState status); - tmpWnd.State = status; + TmpWnd.State = status; } private void wnd_action_overlay_CheckedChanged(object sender, EventArgs e) => - tmpWnd.Overlay = wnd_action_overlay.Checked; + TmpWnd.Overlay = wnd_action_overlay.Checked; private void readerUpdate_Tick(object sender, EventArgs e) { - for (int i = 0; i < readerLabels.Length; i++) + foreach (Label s in _readerLabels) { - Label s = readerLabels[i]; Keys key = (Keys) s.Tag; s.Text = $"{key.ToString()}: {key.IsDown()}"; } @@ -248,17 +265,17 @@ namespace CC_Functions.W32.Test using IDCDrawer drawer = DeskMan.CreateGraphics(); Graphics g = drawer.Graphics; Pen eye = new Pen(new SolidBrush(Color.Red), 2); - g.DrawCurve(eye, new[] {makePoint(20, 50), makePoint(50, 65), makePoint(80, 50)}); - g.DrawCurve(eye, new[] {makePoint(20, 50), makePoint(50, 35), makePoint(80, 50)}); + g.DrawCurve(eye, new[] {MakePoint(20, 50), MakePoint(50, 65), MakePoint(80, 50)}); + g.DrawCurve(eye, new[] {MakePoint(20, 50), MakePoint(50, 35), MakePoint(80, 50)}); g.DrawEllipse(eye, - new RectangleF(PointF.Subtract(makePoint(50, 50), makeSizeY(15, 15)), makeSizeY(30, 30))); + new RectangleF(PointF.Subtract(MakePoint(50, 50), MakeSizeY(15, 15)), MakeSizeY(30, 30))); } - public static PointF makePoint(float xPercent, float yPercent) => new PointF( + private static PointF MakePoint(float xPercent, float yPercent) => new PointF( (Screen.PrimaryScreen.Bounds.Width * xPercent) / 100, (Screen.PrimaryScreen.Bounds.Height * yPercent) / 100); - public static SizeF makeSizeY(float xPercent, float yPercent) => new SizeF( + private static SizeF MakeSizeY(float xPercent, float yPercent) => new SizeF( (Screen.PrimaryScreen.Bounds.Height * xPercent) / 100, (Screen.PrimaryScreen.Bounds.Height * yPercent) / 100); @@ -277,10 +294,10 @@ namespace CC_Functions.W32.Test using IDCDrawer drawer = ScreenMan.GetDrawer(false); Graphics g = drawer.Graphics; Pen eye = new Pen(new SolidBrush(Color.Red), 2); - g.DrawCurve(eye, new[] {makePoint(20, 50), makePoint(50, 65), makePoint(80, 50)}); - g.DrawCurve(eye, new[] {makePoint(20, 50), makePoint(50, 35), makePoint(80, 50)}); + g.DrawCurve(eye, new[] {MakePoint(20, 50), MakePoint(50, 65), MakePoint(80, 50)}); + g.DrawCurve(eye, new[] {MakePoint(20, 50), MakePoint(50, 35), MakePoint(80, 50)}); g.DrawEllipse(eye, - new RectangleF(PointF.Subtract(makePoint(50, 50), makeSizeY(15, 15)), makeSizeY(30, 30))); + new RectangleF(PointF.Subtract(MakePoint(50, 50), MakeSizeY(15, 15)), MakeSizeY(30, 30))); } private void time_set_Click(object sender, EventArgs e) => Time.Set(time_select.Value); diff --git a/W32.Test/Properties/AssemblyInfo.cs b/W32.Test/Properties/AssemblyInfo.cs deleted file mode 100644 index ebfc423..0000000 --- a/W32.Test/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("W32.Test")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("W32.Test")] -[assembly: AssemblyCopyright("Copyright © 2019")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("6121a6d3-7c73-4ede-a5a9-09dc52150824")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.1.*")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/W32.Test/Properties/Resources.Designer.cs b/W32.Test/Properties/Resources.Designer.cs deleted file mode 100644 index 6784b3d..0000000 --- a/W32.Test/Properties/Resources.Designer.cs +++ /dev/null @@ -1,63 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace CC_Functions.W32.Test.Properties { - using System; - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CC_Functions.W32.Test.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - } -} diff --git a/W32.Test/Properties/Resources.resx b/W32.Test/Properties/Resources.resx deleted file mode 100644 index af7dbeb..0000000 --- a/W32.Test/Properties/Resources.resx +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/W32.Test/Properties/Settings.Designer.cs b/W32.Test/Properties/Settings.Designer.cs deleted file mode 100644 index 2eaa818..0000000 --- a/W32.Test/Properties/Settings.Designer.cs +++ /dev/null @@ -1,26 +0,0 @@ -//------------------------------------------------------------------------------ -// -// This code was generated by a tool. -// Runtime Version:4.0.30319.42000 -// -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// -//------------------------------------------------------------------------------ - -namespace CC_Functions.W32.Test.Properties { - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.3.0.0")] - internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default { - get { - return defaultInstance; - } - } - } -} diff --git a/W32.Test/Properties/Settings.settings b/W32.Test/Properties/Settings.settings deleted file mode 100644 index 3964565..0000000 --- a/W32.Test/Properties/Settings.settings +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/W32.Test/W32.Test.csproj b/W32.Test/W32.Test.csproj index 54a3eeb..42bf290 100644 --- a/W32.Test/W32.Test.csproj +++ b/W32.Test/W32.Test.csproj @@ -5,8 +5,6 @@ CC_Functions.W32.Test CC_Functions.W32.Test 8 - enable - false true false @@ -14,10 +12,10 @@ if exist "$(SolutionDir)Data\pkgtool.exe" ($(SolutionDir)Data\pkgtool.exe build --noLogo --binDir .) else if exist "%appdata%\UpTool2\Apps\0e35d154-d0d3-45e0-b080-62f521263a44\app\pkgtool.exe" ("%appdata%\UpTool2\Apps\0e35d154-d0d3-45e0-b080-62f521263a44\app\pkgtool.exe" build --noLogo --binDir .) else echo Cound not find Package build tools, skipping - bin\Debug\W32.Test.xml + - bin\Release\W32.Test.xml + diff --git a/W32/DeskMan.cs b/W32/DeskMan.cs index 20b2c63..e620420 100644 --- a/W32/DeskMan.cs +++ b/W32/DeskMan.cs @@ -15,8 +15,8 @@ namespace CC_Functions.W32 get { using (Bitmap bmpTemp = - new Bitmap(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + - @"\Microsoft\Windows\Themes\TranscodedWallpaper")) + new Bitmap( + $@"{Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\Microsoft\Windows\Themes\TranscodedWallpaper")) { return (Image) bmpTemp.Clone(); } diff --git a/W32/Hooks/MouseHookEventArgs.cs b/W32/Hooks/MouseHookEventArgs.cs index 9873395..08a0e3c 100644 --- a/W32/Hooks/MouseHookEventArgs.cs +++ b/W32/Hooks/MouseHookEventArgs.cs @@ -14,6 +14,6 @@ namespace CC_Functions.W32.Hooks public Point Point { get; } public MouseHook.MouseMessages Message { get; } - public override string ToString() => Message + "; " + Point; + public override string ToString() => $"{Message}; {Point}"; } } \ No newline at end of file diff --git a/W32/W32.csproj b/W32/W32.csproj index c3b72ff..574a554 100644 --- a/W32/W32.csproj +++ b/W32/W32.csproj @@ -4,12 +4,9 @@ CC_Functions.W32 CC-Functions.W32 8 - enable - true true net461;netcoreapp3.1 false - CC24 W32 Additions for CC-Functions Copyright 2020 diff --git a/W32/Wnd32.cs b/W32/Wnd32.cs index 409d9b3..801316c 100644 --- a/W32/Wnd32.cs +++ b/W32/Wnd32.cs @@ -54,6 +54,14 @@ namespace CC_Functions.W32 /// The window. Might be IntPtr.Zero public static Wnd32 FromPoint(Point point) => FromHandle(user32.WindowFromPoint(point.X, point.Y)); + /// + /// Gets all windows at the specific point + /// + /// The point to scan + /// Whether windows need to be visible + /// The windows + public static Wnd32[] AllFromPoint(Point point, bool visible = false) => All.Where(s => s.Position.Contains(point) && s.Shown || !visible).ToArray(); + /// /// Gets the window associated with the forms handle /// @@ -72,15 +80,15 @@ namespace CC_Functions.W32 _windowHandles = new List(); if (!user32.EnumDesktopWindows(IntPtr.Zero, FilterCallback, IntPtr.Zero)) throw new Win32Exception("There was a native error. This should never happen!"); - return _windowHandles.Select(s => FromHandle(s)).ToArray(); + return _windowHandles.Select(FromHandle).ToArray(); } } /// - /// Gets all visible windows with valid titles + /// Gets all visible windows /// public static Wnd32[] Visible => - All.Where(s => user32.IsWindowVisible(s.HWnd) && !string.IsNullOrEmpty(s.Title)).ToArray(); + All.Where(s => s.Shown).ToArray(); /// /// Gets the foreground window