隱藏窗口同樣要使用win32 API,函數為ShowWindow.
具體使用請參閱MSDN.

解决方案 »

  1.   

    给楼主一个查找包含有指定字符串的标题的所有窗口的代码,仅供参考,仅供参考:
    internal delegate bool EnumThreadWindowsCallback(IntPtr hWnd, IntPtr lParam);
    internal delegate bool EnumChildrenCallback(IntPtr hwnd, IntPtr lParam);[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    internal static extern bool EnumWindows(EnumThreadWindowsCallback callback, IntPtr extraData);[DllImport("user32.dll", ExactSpelling = true)]
    internal static extern bool EnumChildWindows(HandleRef hwndParent, EnumChildrenCallback lpEnumFunc, HandleRef lParam);[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
    internal static extern int GetWindowThreadProcessId(HandleRef handle, out int processId);[DllImport("user32.dll", CharSet = CharSet.Auto)]
    internal static extern int GetWindowText(HandleRef hWnd, StringBuilder lpString, int nMaxCount);[DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern int GetWindowTextLength(HandleRef hWnd);private bool EnumWindowsCallback(IntPtr handle, IntPtr extraParameter)
    {
    int capacity = GetWindowTextLength(new HandleRef(this, handle)) * 2;
    StringBuilder lpString = new StringBuilder(capacity);
    GetWindowText(new HandleRef(this, handle), lpString, lpString.Capacity);
    if (lpString.Length > 0 && lpString.ToString().IndexOf("工程") != -1)
    {
    Console.WriteLine(lpString.ToString()); EnumChildWindows(new HandleRef(null, handle), new EnumChildrenCallback(EnumChildWindowsCallBack), new HandleRef(null, IntPtr.Zero));
    }
    return true;
    }private bool EnumChildWindowsCallBack(IntPtr handle, IntPtr lparam)
    {
    int capacity = GetWindowTextLength(new HandleRef(this, handle)) * 2;
    StringBuilder lpString = new StringBuilder(capacity);
    GetWindowText(new HandleRef(this, handle), lpString, lpString.Capacity);
    if (lpString.Length > 0 && lpString.ToString().IndexOf("工程") != -1)
    {
    Console.WriteLine(lpString.ToString());
    EnumChildWindows(new HandleRef(null, handle), new EnumChildrenCallback(EnumChildWindowsCallBack), new HandleRef(null, IntPtr.Zero));
    } return true;
    }private void button1_Click(object sender, EventArgs e)
    {
    EnumThreadWindowsCallback callback = new EnumThreadWindowsCallback(this.EnumWindowsCallback);
    EnumWindows(callback, IntPtr.Zero);
    }
      

  2.   

    上面的代码只是找到相应的窗口,但没有隐藏,可以使用如下API:[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpelling=true)]
    public static extern bool ShowWindow(HandleRef hWnd, int nCmdShow);
      

  3.   

    四楼正解,使用windows的一个窗口枚举器.