Test with EnumChildWindows =>
(add a button for the click)
public partial class Form1 : Form
{
public delegate bool EnumChildCallback(IntPtr hwnd, ref IntPtr lParam);
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool EnumChildWindows(IntPtr hWndParent, EnumChildCallback lpEnumFunc, ref IntPtr lParam);
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
EnumChildCallback ecb = new EnumChildCallback(EnumChildProc);
IntPtr pPtr = IntPtr.Zero;
EnumChildWindows(this.Handle, ecb, ref pPtr);
}
public static bool EnumChildProc(IntPtr hwndChild, ref IntPtr lParam)
{
StringBuilder sbBufferText = new StringBuilder(260);
GetClassName(hwndChild, sbBufferText, sbBufferText.Capacity);
StringBuilder sbBufferText2 = new StringBuilder(260);
GetWindowText(hwndChild, sbBufferText2, sbBufferText2.Capacity);
Console.WriteLine("Window : {0:x}", hwndChild.ToInt32());
Console.WriteLine("\tClass : {0}", sbBufferText.ToString());
Console.WriteLine("\tText : {0}", sbBufferText2.ToString());
return true;
}
}