コード例 #1
0
        public void Enumerate_Take10()
        {
            var result = WindowsEnumerator.EnumerateWindows().Take(10).Count(window => window != null);

            if (result != 10)
            {
                throw new Exception($"Expected 10, actual {result}");
            }
        }
コード例 #2
0
        public void Enumerate_LimitFunc()
        {
            var result = WindowsEnumerator.EnumerateWindows(null, null, (window, i) => i < 10).Count(window => window != null);

            if (result != 10)
            {
                throw new Exception($"Expected 10, actual {result}");
            }
        }
コード例 #3
0
        public void EnumerateAll()
        {
            var result = WindowsEnumerator.EnumerateWindows().All(window => window != null);

            if (!result)
            {
                throw new ArgumentNullException();
            }
        }
コード例 #4
0
        private void EnumerateWindows_Take10()
        {
            var windows = WindowsEnumerator.EnumerateWindows().Take(10).ToList();

            Assert.True(windows.Count == 10);
        }
コード例 #5
0
        private void EnumerateWindows()
        {
            var windows = WindowsEnumerator.EnumerateWindows().ToList();

            Assert.True(windows.Count > 0);
        }
コード例 #6
0
        /// <summary>
        ///     Test scrolling a window
        /// </summary>
        /// <returns></returns>
        //[StaFact]
        private async Task TestScrollingAsync()
        {
            var breakScroll = false;

            IDisposable keyboardhook = null;

            try
            {
                keyboardhook = KeyboardHook.KeyboardEvents.Where(args => args.Key == VirtualKeyCode.Escape).Subscribe(args => breakScroll = true);
                // Start a process to test against
                using (var process = Process.Start("notepad.exe", "C:\\Windows\\setupact.log"))
                {
                    // Make sure it's started
                    Assert.NotNull(process);
                    // Wait until the process started it's message pump (listening for input)
                    process.WaitForInputIdle();

                    try
                    {
                        // Find the belonging window, by the process id
                        var notepadWindow = WindowsEnumerator.EnumerateWindows()
                                            .FirstOrDefault(interopWindow =>
                        {
                            User32Api.GetWindowThreadProcessId(interopWindow.Handle, out var processId);
                            return(processId == process.Id);
                        });
                        Assert.NotNull(notepadWindow);

                        // Create a WindowScroller
                        var scroller = notepadWindow.GetChildren().Select(window => window.GetWindowScroller()).FirstOrDefault();

                        Assert.NotNull(scroller);
                        // Notepad should have ScrollBarInfo
                        scroller.GetScrollbarInfo();
                        Assert.True(scroller.ScrollBar.HasValue);

                        Log.Info().WriteLine("Scrollbar info: {0}", scroller.ScrollBar.Value);

                        User32Api.SetForegroundWindow(scroller.ScrollingWindow.Handle);
                        await Task.Delay(1000);

                        // Just make sure the window is changed
                        KeyboardInputGenerator.KeyPresses(VirtualKeyCode.Next, VirtualKeyCode.Down);
                        await Task.Delay(2000);

                        scroller.ScrollMode  = ScrollModes.WindowsMessage;
                        scroller.ShowChanges = false;
                        // Move the window to the start
                        Assert.True(scroller.Start());
                        // A delay to make the window move
                        await Task.Delay(2000);

                        // Check if it did move to the start
                        Assert.True(scroller.IsAtStart);

                        // Loop
                        do
                        {
                            if (breakScroll)
                            {
                                break;
                            }
                            // Next "page"
                            Assert.True(scroller.Next());
                            // Wait a bit, so the window can update
                            await Task.Delay(300);

                            // Loop as long as we are not at the end yet
                        } while (!scroller.IsAtEnd);
                        scroller.Reset();
                    }
                    finally
                    {
                        // Kill the process
                        process.Kill();
                    }
                }
            }
            finally
            {
                keyboardhook?.Dispose();
            }
        }
コード例 #7
0
 /// <summary>
 ///     Get Windows displaying an IE
 /// </summary>
 /// <returns>IEnumerable IInteropWindow</returns>
 public static IEnumerable <IInteropWindow> GetIeWindows()
 {
     return(WindowsEnumerator.EnumerateWindows().Where(IsIeWindow));
 }