FindWindow fw = new FindWindow(wndHandle, "ChildwndClassName"); //实例化,第一个参数是要查找的起始窗口的句柄;第二个参数是要查找的窗口的类的名称。现在我们需要的传的是"Internet Explorer_Server"。
IntPtr ip = fw.FoundHandle;//FindWindow的公共属性FoundHandle就是查找到的窗口的句柄。
完整的类如下:
using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace SystemManager.Utility ...{
/**////<summary> /// This class is to find the given window's child window accroding to the given child window's name. /// The useage: FindWindow fw = new FindWindow(wndHandle, "ChildwndClassName"); IntPtr ip = fw.FoundHandle; /// I adapt the code from Paul DiLascia,who is the MSDN Magazine's writer. /// The original class is named CFindWnd which is written in C++, and you could get it on Internet. /// www.pinvoke.net is a great website.It includes almost all the API fuctoin to be used in C#. ///</summary> class FindWindow ...{
[DllImport("user32")] [return: MarshalAs(UnmanagedType.Bool)] //IMPORTANT : LPARAM must be a pointer (InterPtr) in VS2005, otherwise an exception will be thrown privatestaticexternbool EnumChildWindows(IntPtr window, EnumWindowProc callback, IntPtr i); //the callback function for the EnumChildWindows privatedelegatebool EnumWindowProc(IntPtr hWnd, IntPtr parameter); //if found return the handle , otherwise return IntPtr.Zero [DllImport("user32.dll", EntryPoint ="FindWindowEx")] privatestaticextern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter,