Exemplo n.º 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
            };
        }
Exemplo n.º 2
0
        public static void Click(IntPtr handle, Location location)
        {
            if (location != null)
            {
                var p = new PInvoke.POINT(); // DOESN'T WORK! not getting clicked!
                p.X = location.X;
                p.Y = location.Y;
                PInvoke.ScreenToClient(handle, ref p);
                var lParam = p.X | (p.Y << 16);

                unsafe
                {
                    PInvoke.SendMessage(handle, PInvoke.WM_LBUTTONDOWN, (IntPtr)0x1, new IntPtr(&p));
                    PInvoke.SendMessage(handle, PInvoke.WM_LBUTTONUP, (IntPtr)0x1, new IntPtr(&p));
                }
            }
            else
            {
                PInvoke.SendMessage(handle, PInvoke.WM_LBUTTONDOWN, (IntPtr)0x1, (IntPtr)0);
                PInvoke.SendMessage(handle, PInvoke.WM_LBUTTONUP, (IntPtr)0x1, (IntPtr)0);
            }
        }