Example #1
0
        public Window(Process p)
        {
            this.p = p;
            IntPtr h = p.Handle;

            while (h == IntPtr.Zero || !p.Responding)
            {
                Sleep(1000);
                p.WaitForInputIdle();
                h = p.Handle;
                if (p.HasExited)
                {
                    throw new InvalidOperationException(string.Format("Process '{0}' has exited!", p.StartInfo.FileName));
                }
            }
            p.Exited += new EventHandler(OnExited);
            int id = p.Id;

            if (handle == IntPtr.Zero)
            {
                // p.MainWindowHandle always returns 0 for some unknown reason...
                int retries = 20;
                while (retries-- > 0 && handle == IntPtr.Zero)
                {
                    handle = FindWindowForProcessId(id);
                    Sleep(1000);
                }
                if (handle == IntPtr.Zero)
                {
                    throw new Exception("Process as no window handle");
                }
            }
            this.acc = SystemAccessible.AccessibleObjectForWindow(handle);
        }
Example #2
0
        public static SystemAccessible AccessibleWindowObjectAt(Point pt)
        {
            POINT p = new POINT();

            p.x = pt.X;
            p.y = pt.Y;
            IntPtr hwnd = WindowFromPoint(p);

            if (hwnd != IntPtr.Zero)
            {
                return(SystemAccessible.AccessibleObjectForWindow(hwnd));
            }
            return(null);
        }
Example #3
0
        private static IntPtr FindWindowForProcessId(int id)
        {
            // Hmmm, try and find window for this process then.
            IntPtr hwnd = GetWindow(GetDesktopWindow(), GetWindowOptions.Child);

            while (hwnd != IntPtr.Zero)
            {
                int procid;
                int thread = GetWindowThreadProcessId(hwnd, out procid);
                if (procid == id && IsWindowVisible(hwnd))
                {
                    SystemAccessible acc = SystemAccessible.AccessibleObjectForWindow(hwnd);
                    if (acc.Role == AccessibleRole.Client &&
                        (acc.State & AccessibleStates.Invisible) == 0 &&
                        !string.IsNullOrEmpty(acc.Name))
                    {
                        // found it!
                        return(hwnd);
                    }
                }
                hwnd = GetWindow(hwnd, GetWindowOptions.Next);
            }
            return(IntPtr.Zero);
        }
Example #4
0
 public Window(Window parent, IntPtr handle)
 {
     this.parent = parent;
     this.handle = handle;
     this.acc    = SystemAccessible.AccessibleObjectForWindow(handle);
 }