[DllImport("User32.dll", EntryPoint = "FindWindow")]
public static extern IntPtr FindWindow(String className, String captionName);
[DllImport("User32.dll", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("User32.dll", EntryPoint = "SendMessage")]
public static extern string SendMessage(IntPtr hWnd, int Msg, int wParm, int lParm);
[DllImport("User32.dll", EntryPoint = "GetWindowText")]
public static extern int GetWindowText(IntPtr hwnd, StringBuilder lpString, int cch);
public IntPtr getHandleParent(string classname, string captionname)
{
IntPtr handle = FindWindow(classname, captionname);
return handle;
}
public IntPtr getHandleChild(IntPtr hwndparent, string lpszclass, string lpszwindow)
{
IntPtr handle = IntPtr.Zero;
if (hwndparent != IntPtr.Zero)
{
handle = FindWindowEx(hwndparent,handle,lpszclass, lpszwindow);
}
else
{
MessageBox.Show("没有找到子窗口");
}
return handle;
}
public string getTxt(IntPtr ChildHandle)
{
StringBuilder s = new StringBuilder();
if (ChildHandle != IntPtr.Zero)
{
int i = GetWindowText(ChildHandle, s, s.Capacity);
}
else
{
MessageBox.Show("子窗口中没有内容");
}
return s.ToString();
}