private static WinComponent FromHandle(IntPtr hwndCur) { var chArWindowClass = new StringBuilder(257); PInvoke.GetClassName(hwndCur, chArWindowClass, 256); var strWndClass = chArWindowClass.ToString(); var length = PInvoke.GetWindowTextLength(hwndCur); var sb = new StringBuilder(length + 1); PInvoke.GetWindowText(hwndCur, sb, sb.Capacity); PInvoke.RECT rct; PInvoke.GetWindowRect(hwndCur, out rct); var style = PInvoke.GetWindowLong(hwndCur, PInvoke.GWL_STYLE); var res = new WinComponent(strWndClass, sb.ToString(), hwndCur, rct.Left, rct.Top, style); return(res); }
private static void RecurseFindWindow(IntPtr hWndParent, List <WinComponent> childs) { if (hWndParent == IntPtr.Zero) { return; } var pointers = new List <IntPtr>(); IntPtr hwndCur = PInvoke.GetWindow(hWndParent, (uint)PInvoke.GetWindowFlags.GW_HWNDFIRST); do { pointers.Add(hwndCur); var chArWindowClass = new StringBuilder(257); PInvoke.GetClassName(hwndCur, chArWindowClass, 256); var strWndClass = chArWindowClass.ToString(); var length = PInvoke.GetWindowTextLength(hwndCur); var sb = new StringBuilder(length + 1); PInvoke.GetWindowText(hwndCur, sb, sb.Capacity); PInvoke.RECT rct; PInvoke.GetWindowRect(hwndCur, out rct); var style = PInvoke.GetWindowLong(hwndCur, PInvoke.GWL_STYLE); childs.Add(new WinComponent(strWndClass, sb.ToString(), hwndCur, rct.Left, rct.Top, style)); hwndCur = PInvoke.GetWindow(hwndCur, (uint)PInvoke.GetWindowFlags.GW_HWNDNEXT); } while (hwndCur != IntPtr.Zero); foreach (var pointer in pointers) { RecurseFindWindow(PInvoke.GetWindow(pointer, (uint)PInvoke.GetWindowFlags.GW_CHILD), childs); } }