Allow finding window children
This commit is contained in:
parent
46bfdfe49e
commit
1d20e11439
31
W32.Test/MainForm.Designer.cs
generated
31
W32.Test/MainForm.Designer.cs
generated
@ -64,6 +64,7 @@
|
||||
this.wnd_select_selected = new System.Windows.Forms.Label();
|
||||
this.wnd_select_self = new System.Windows.Forms.Button();
|
||||
this.wnd = new System.Windows.Forms.GroupBox();
|
||||
this.wnd_select_child = new System.Windows.Forms.Button();
|
||||
this.wnd_select_list = new System.Windows.Forms.Button();
|
||||
this.wnd_action_overlay = new System.Windows.Forms.CheckBox();
|
||||
this.wnd_action_style = new System.Windows.Forms.ComboBox();
|
||||
@ -83,8 +84,8 @@
|
||||
this.desk_back = new System.Windows.Forms.Panel();
|
||||
this.readerUpdate = new System.Windows.Forms.Timer(this.components);
|
||||
this.time = new System.Windows.Forms.GroupBox();
|
||||
this.time_select = new System.Windows.Forms.DateTimePicker();
|
||||
this.time_set = new System.Windows.Forms.Button();
|
||||
this.time_select = new System.Windows.Forms.DateTimePicker();
|
||||
this.keyboard.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize) (this.wnd_action_pos_h_bar)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize) (this.wnd_action_pos_w_bar)).BeginInit();
|
||||
@ -442,7 +443,7 @@
|
||||
this.wnd_select_title_box.Size = new System.Drawing.Size(121, 23);
|
||||
this.wnd_select_title_box.TabIndex = 6;
|
||||
//
|
||||
// wnd_selet_class_button
|
||||
// wnd_select_class_button
|
||||
//
|
||||
this.wnd_select_class_button.Location = new System.Drawing.Point(7, 89);
|
||||
this.wnd_select_class_button.Name = "wnd_select_class_button";
|
||||
@ -483,6 +484,7 @@
|
||||
//
|
||||
// wnd
|
||||
//
|
||||
this.wnd.Controls.Add(this.wnd_select_child);
|
||||
this.wnd.Controls.Add(this.wnd_select_list);
|
||||
this.wnd.Controls.Add(this.wnd_action_overlay);
|
||||
this.wnd.Controls.Add(this.wnd_action_style);
|
||||
@ -516,6 +518,16 @@
|
||||
this.wnd.TabStop = false;
|
||||
this.wnd.Text = "CC-Functions.W32.Wnd32";
|
||||
//
|
||||
// wnd_select_child
|
||||
//
|
||||
this.wnd_select_child.Location = new System.Drawing.Point(107, 122);
|
||||
this.wnd_select_child.Name = "wnd_select_child";
|
||||
this.wnd_select_child.Size = new System.Drawing.Size(94, 27);
|
||||
this.wnd_select_child.TabIndex = 27;
|
||||
this.wnd_select_child.Text = "Select (childs)";
|
||||
this.wnd_select_child.UseVisualStyleBackColor = true;
|
||||
this.wnd_select_child.Click += new System.EventHandler(this.wnd_select_child_Click);
|
||||
//
|
||||
// wnd_select_list
|
||||
//
|
||||
this.wnd_select_list.Location = new System.Drawing.Point(7, 122);
|
||||
@ -740,13 +752,6 @@
|
||||
this.time.TabStop = false;
|
||||
this.time.Text = "CC-Functions.W32.Time";
|
||||
//
|
||||
// time_select
|
||||
//
|
||||
this.time_select.Location = new System.Drawing.Point(6, 26);
|
||||
this.time_select.Name = "time_select";
|
||||
this.time_select.Size = new System.Drawing.Size(205, 23);
|
||||
this.time_select.TabIndex = 0;
|
||||
//
|
||||
// time_set
|
||||
//
|
||||
this.time_set.Location = new System.Drawing.Point(217, 22);
|
||||
@ -757,6 +762,13 @@
|
||||
this.time_set.UseVisualStyleBackColor = true;
|
||||
this.time_set.Click += new System.EventHandler(this.time_set_Click);
|
||||
//
|
||||
// time_select
|
||||
//
|
||||
this.time_select.Location = new System.Drawing.Point(6, 27);
|
||||
this.time_select.Name = "time_select";
|
||||
this.time_select.Size = new System.Drawing.Size(205, 23);
|
||||
this.time_select.TabIndex = 0;
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||
@ -851,5 +863,6 @@
|
||||
private System.Windows.Forms.GroupBox time;
|
||||
private System.Windows.Forms.DateTimePicker time_select;
|
||||
private System.Windows.Forms.Button time_set;
|
||||
private System.Windows.Forms.Button wnd_select_child;
|
||||
}
|
||||
}
|
@ -83,6 +83,8 @@ namespace CC_Functions.W32.Test
|
||||
private void wnd_select_list_Click(object sender, EventArgs e) =>
|
||||
TmpWnd = SelectBox.Show(Wnd32.Visible, "Please select a window") ?? TmpWnd;
|
||||
|
||||
private void wnd_select_child_Click(object sender, EventArgs e) => TmpWnd = SelectBox.Show(TmpWnd.Children, "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);
|
||||
|
||||
|
@ -6,6 +6,7 @@ namespace CC_Functions.W32.Native
|
||||
{
|
||||
internal static class user32
|
||||
{
|
||||
public delegate bool EnumWindowProc(IntPtr hWnd, IntPtr lParam);
|
||||
public delegate bool EnumDelegate(IntPtr hWnd, int lParam);
|
||||
|
||||
public delegate IntPtr LowLevelProc(int nCode, IntPtr wParam, IntPtr lParam);
|
||||
@ -129,5 +130,9 @@ namespace CC_Functions.W32.Native
|
||||
|
||||
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall)]
|
||||
public static extern void mouse_event(uint dwFlags, uint dx, uint dy, uint cButtons, uint dwExtraInfo);
|
||||
|
||||
[DllImport("user32")]
|
||||
[return: MarshalAs(UnmanagedType.Bool)]
|
||||
public static extern bool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr lParam);
|
||||
}
|
||||
}
|
35
W32/Wnd32.cs
35
W32/Wnd32.cs
@ -4,6 +4,7 @@ using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using CC_Functions.W32.Native;
|
||||
@ -104,6 +105,28 @@ namespace CC_Functions.W32
|
||||
|
||||
#region InstanceActions
|
||||
|
||||
public Wnd32[] Children
|
||||
{
|
||||
get
|
||||
{
|
||||
List<IntPtr> childHandles = new List<IntPtr>();
|
||||
|
||||
GCHandle gcChildHandlesList = GCHandle.Alloc(childHandles);
|
||||
IntPtr pointerChildHandlesList = GCHandle.ToIntPtr(gcChildHandlesList);
|
||||
|
||||
try
|
||||
{
|
||||
user32.EnumChildWindows(HWnd, EnumWindow, pointerChildHandlesList);
|
||||
}
|
||||
finally
|
||||
{
|
||||
gcChildHandlesList.Free();
|
||||
}
|
||||
|
||||
return childHandles.Select(FromHandle).ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The windows title
|
||||
/// </summary>
|
||||
@ -345,6 +368,18 @@ namespace CC_Functions.W32
|
||||
return true;
|
||||
}
|
||||
|
||||
private bool EnumWindow(IntPtr hWnd, IntPtr lParam)
|
||||
{
|
||||
GCHandle gcChildhandlesList = GCHandle.FromIntPtr(lParam);
|
||||
|
||||
if (gcChildhandlesList.Target == null) return false;
|
||||
|
||||
List<IntPtr> childHandles = gcChildhandlesList.Target as List<IntPtr>;
|
||||
childHandles?.Add(hWnd);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion Internal
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user