Exemplo n.º 1
0
        private static List <ControlHandle> GetFromProcess(Process process)
        {
            var resultWindowsList = new List <ControlHandle>();

            WindowsMethods.EnumWindows((hWnd, _) =>
            {
                ControlHandle control = hWnd;
                if (control.IsAppWindow())
                {
                    if (process.Id > 0)
                    {
                        var windowProcessId = 0;
                        WindowsMethods.GetWindowThreadProcessId(control, ref windowProcessId);
                        if (windowProcessId == process.Id)
                        {
                            resultWindowsList.Add(control);
                        }
                    }
                    else
                    {
                        resultWindowsList.Add(control);
                    }
                }
                return(true);
            }, 0);
            return(resultWindowsList);
        }
Exemplo n.º 2
0
        public bool IsAppWindow()
        {
            if (IsVisibleWindow())
            {
                var stylex = WindowsMethods.GetWindowLong(Handle, WindowsMethods.GWL_ExStyle);
                if (WindowsMethods.WSEX_ApplicationWindow != (stylex & WindowsMethods.WSEX_ApplicationWindow))
                {
                    var style = WindowsMethods.GetWindowLong(Handle, WindowsMethods.GWL_Style);
                    if (IntPtr.Zero.Equals(WindowsMethods.GetWindowLongish(Handle, WindowsMethods.GWL_HWndParent)) &&
                        IntPtr.Zero.Equals(WindowsMethods.GetWindow(Handle, WindowsMethods.GW_Owner)) &&
                        WindowsMethods.WS_Child != (style & WindowsMethods.WS_Child))
                    {
                        if (WindowsMethods.WSEX_ToolWindow == (stylex & WindowsMethods.WSEX_ToolWindow))
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                var windowClass = WindowsMethods.GetClassName(Handle);

                if (windowClass.Equals("WindowsScreensaverClass") || windowClass.Equals("tooltips_class32"))
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 3
0
        private List <ControlHandle> GetAllControls()
        {
            var controlsList = new List <ControlHandle>();

            WindowsMethods.EnumChildWindows(Handle, (hWnd, param) =>
            {
                controlsList.Add(hWnd);
                return(true);
            }, 0);
            return(controlsList);
        }
Exemplo n.º 4
0
        public IEnumerable <ControlHandle> GetChildrenWindows()
        {
            ControlHandle found = WindowsMethods.FindWindowEx(IntPtr.Zero, IntPtr.Zero, null, null);

            while (found.Equals(IntPtr.Zero) == false)
            {
                if (found.IsVisibleWindow() && found.GetParentOrOwner() == Handle)
                {
                    yield return(found);
                }
                found = WindowsMethods.FindWindowEx(IntPtr.Zero, found, null, null);
            }
        }
Exemplo n.º 5
0
 private bool IsVisibleWindow()
 {
     return(WindowsMethods.IsWindow(Handle) && WindowsMethods.IsWindowVisible(Handle));
 }
Exemplo n.º 6
0
 public ControlHandle(IntPtr handle)
 {
     Handle = handle;
     Title  = WindowsMethods.GetWindowCaption(handle);
     Class  = WindowsMethods.GetClassName(handle);
 }
Exemplo n.º 7
0
 public void Activate()
 {
     WindowsMethods.SetForegroundWindow(this);
 }
Exemplo n.º 8
0
 private IntPtr GetParentOrOwner()
 {
     return(WindowsMethods.GetParent(Handle));
 }
Exemplo n.º 9
0
 private string GetClassName()
 {
     return(WindowsMethods.GetClassName(this));
 }