Добрый день.Нужно в стороннем приложении, в дочернем окне нажать конпку.Стартую приложение,открываю дочернее окно - не могу получить handle дочернего окна(form2).C winApi только начинаю.
[DllImport("user32.dll")]
public static extern int FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);
[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
private const int BN_CLICKED = 245;
IntPtr hwndChild = IntPtr.Zero;
IntPtr hwndChild2 = IntPtr.Zero;
IntPtr hwnd = IntPtr.Zero;
IntPtr hwnd2 = IntPtr.Zero;
private void button1_Click(object sender, EventArgs e)
{
Process.Start(@"C:\file.exe");
System.Threading.Thread.Sleep(5000);
hwnd = (IntPtr)FindWindow(null, "создать документ");//получаем handle родительского окна
//textBox1.Text = hwnd.ToString();
hwndChild = FindWindowEx((IntPtr)hwnd, IntPtr.Zero,
"WindowsForms10.BUTTON.app.0.378734a", "о программе");
SendMessage((int)hwndChild, BN_CLICKED, 0, (int)IntPtr.Zero);//нажимаем на кнопку и выводим окно
System.Threading.Thread.Sleep(5000);
hwnd2 = (IntPtr)FindWindow(null, "form2"); //здесь 0
textBox2.Text = hwnd2.ToString(); //здесь 0
hwndChild2 = FindWindowEx((IntPtr)hwnd2, IntPtr.Zero,
"WindowsForms10.BUTTON.app.0.378734a", "выход");
SendMessage((int)hwndChild2, BN_CLICKED, 0, (int)IntPtr.Zero);
}