RT

解决方案 »

  1.   

    先有主窗口,然后 EnumChildWindows API 可以做到了
      
    --------------------------------------------------------------
    程序,犹如人生。
      

  2.   

    http://www.codeproject.com/csharp/controlinspector.asp模拟一个Spy++
      

  3.   

    在主窗体中,this.MdiChildren就能得到所有的子窗体
      

  4.   

    如下代码可以得到所有窗口及其子窗口的名柄及标题,如果要得到子子窗口的可以用递归,但我没有用:[DllImport("user32.dll", CharSet = CharSet.Auto)]
    private static extern int GetWindowText(HandleRef hWnd, StringBuilder lpString, int nMaxCount);
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    private static extern int GetWindowTextLength(HandleRef hWnd);
    [DllImport("user32.dll", CharSet=CharSet.Auto, SetLastError=true)]
    private static extern bool EnumWindows(EnumThreadWindowsCallback callback, IntPtr extraData);
    [DllImport("user32.dll", ExactSpelling = true)]
    private static extern bool EnumChildWindows(HandleRef hwndParent, EnumChildrenCallback lpEnumFunc, HandleRef lParam);
    private delegate bool EnumThreadWindowsCallback(IntPtr hWnd, IntPtr lParam);
    private delegate bool EnumChildrenCallback(IntPtr hwnd, IntPtr lParam);private void button1_Click(object sender, EventArgs e)
    {
    EnumThreadWindowsCallback callback1 = new EnumThreadWindowsCallback(this.EnumWindowsCallback);
    EnumWindows(callback1, IntPtr.Zero);
    }
    private bool EnumWindowsCallback(IntPtr handle, IntPtr extraParameter)
    {
    int num1 = GetWindowTextLength(new HandleRef(this, handle)) * 2;
    StringBuilder builder1 = new StringBuilder(num1);
    GetWindowText(new HandleRef(this, handle), builder1, builder1.Capacity);
    System.Console.WriteLine(string.Format("Wnd:{0} Title: {1}", handle,builder1.ToString())); EnumChildWindows(new HandleRef(this, handle), new EnumChildrenCallback(EnumChildWindowsCallback), new HandleRef(null, IntPtr.Zero));
    return true;
    }
    private bool EnumChildWindowsCallback(IntPtr handle, IntPtr lparam)
    {
    int num1 = GetWindowTextLength(new HandleRef(this, handle)) * 2;
    StringBuilder builder1 = new StringBuilder(num1);
    GetWindowText(new HandleRef(this, handle), builder1, builder1.Capacity);
    System.Console.WriteLine(string.Format("\tSubWnd:{0} Title: {1}", handle, builder1.ToString()));
    return true;
    }