查找窗口 [DllImport(“User32.dll”, EntryPoint = “FindWindow”)] public extern static IntPtr FindWindow( string lpClassName,string lpWindowName);
IntPtr maindHwnd = FindWindow(“WindowsForms10.Window.8.app.0.141b42a_r9_ad1”, null); FindWindow 第一参数是窗口的句柄 第二个参数是窗口得名字
查找子窗口 [DllImport(“User32.dll”, EntryPoint = “FindWindowEx”)] public static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpClassName, string lpWindowName);
IntPtr hwnd = FindWindowEx(maindHwnd, IntPtr.Zero, null, null); 第一个参数是父窗口
遍历窗口 EnumChildWindows(maindHwnd, callBackEnumChildWindows, 0); 其中callBackEnumChildWindows 是回调函数