public static void FilterUnmanagedWindows(WindowTreeNode parentNode) { for (int i = 0; i < parentNode.Nodes.Count; i++) { WindowTreeNode node = (WindowTreeNode)parentNode.Nodes[i]; if (!node.IsManaged)// && !HasManagedChild(node)) { parentNode.Nodes.RemoveAt(i); i--; } else { FilterUnmanagedWindows(node); } } }
private void SetWindowTreeNodeImage(ImageList imageList, WindowTreeNode node) { this.SetNodeImage(imageList, node); if (node.Nodes.Count > 0) { foreach (WindowTreeNode subNode in node.Nodes) { this.SetWindowTreeNodeImage(imageList, subNode); } } }
private void SetNodeImage(ImageList imageList, WindowTreeNode node) { IntPtr hIcon = NativeMethods.GetClassLongPtr(node.Hwnd, NativeMethods.GCLP_HICON); if (IntPtr.Zero == hIcon) { if (node.IsManaged) { imageList.Images.Add(node.Hwnd.ToString(), Resources.DotNetWindow); } else { imageList.Images.Add(node.Hwnd.ToString(), Resources.Window); } } else { Icon icon = Icon.FromHandle(hIcon); if (null == icon) { hIcon = NativeMethods.SendMessage( node.Hwnd, NativeMethods.WM_GETICON, new IntPtr(NativeMethods.ICON_BIG), IntPtr.Zero); } if (null != icon) { imageList.Images.Add(node.Hwnd.ToString(), icon); } } node.ImageKey = node.Hwnd.ToString(); node.SelectedImageKey = node.Hwnd.ToString(); node.StateImageKey = node.Hwnd.ToString(); }
public bool HasManagedChild(WindowTreeNode parentNode) { bool ret = false; foreach(WindowTreeNode node in parentNode.Nodes) { if (node.IsManaged || HasManagedChild(node)) { ret = true; break; } } return ret; }
private WindowTreeNode AddWindowNode(WindowTreeNode node) { IntPtr hwndParent = NativeMethods.GetParent(node.Hwnd); if (hwndNodeMap.ContainsKey(hwndParent)) { WindowTreeNode parentNode = (WindowTreeNode)hwndNodeMap[hwndParent]; if (parentNode != null) parentNode.Nodes.Add(node); } else { this.RootNode.Nodes.Add(node); } return node; }
private WindowTreeNode AddWindow(IntPtr hwnd, bool isManaged) { WindowTreeNode node = new WindowTreeNode(hwnd, isManaged); if (!isManaged) { NativeWindow native = new NativeWindow(); native.Handle = hwnd; native.ClassName = node.WindowClassName; native.Text = node.WindowText; node.Tag = native; } if (!hwndNodeMap.ContainsKey(hwnd)) hwndNodeMap[hwnd] = node; return node; }