예제 #1
0
        static void ComputeRectRelativeToParent(IntPtr hWnd, IntPtr hwndParent, out PInvoke.RECT clientParent, out PInvoke.RECT client)
        {
            PInvoke.RECT rw, rc;
            PInvoke.GetWindowRect(hWnd, out rw);
            PInvoke.GetClientRect(hWnd, out rc);

            PInvoke.RECT rpw, rpc;
            PInvoke.GetWindowRect(hwndParent, out rpw);
            PInvoke.GetClientRect(hwndParent, out rpc);

            PInvoke.POINT p0 = new PInvoke.POINT()
            {
                X = rw.Left,
                Y = rw.Top
            };
            PInvoke.ScreenToClient(hwndParent, ref p0);
            PInvoke.POINT p1 = new PInvoke.POINT()
            {
                X = rw.Right,
                Y = rw.Bottom
            };
            PInvoke.ScreenToClient(hwndParent, ref p1);

            clientParent = rpc;
            client       = new PInvoke.RECT()
            {
                Left   = p0.X,
                Top    = p0.Y,
                Right  = p1.X,
                Bottom = p1.Y
            };
        }
예제 #2
0
        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);
            }
        }