Esempio n. 1
0
        private void removeWindow()
        {
            // 关闭窗口
            WindowEntryFactory.CloseWindow(mFocusBtn.Tag as IWindowEntry);

            int index = stackPanel.Children.IndexOf(mFocusBtn);

            mWins.Windows.Remove(mFocusBtn.Tag as IWindowEntry);
            stackPanel.Children.Remove(mFocusBtn);
            // 聚焦到后面一个Window
            if (index < stackPanel.Children.Count)
            {
                stackPanel.Children[index].Focus();
            }
            else if (index > 0)
            {
                stackPanel.Children[index - 1].Focus();
            }
            if (stackPanel.Children.Count == 0)
            {
                HideWin();
            }
            else
            {
                resetWindowSize();
            }
        }
Esempio n. 2
0
        public void GetGetWindowEntry_FromTestWindow()
        {
            using (var app = new GivenAnApp("GoToWindow.GetGetWindowEntry_FromTestWindow"))
            {
                var expectedWindowHandle = app.Process.MainWindowHandle;
                var window = WindowEntryFactory.Create(expectedWindowHandle);

                Assert.AreEqual(expectedWindowHandle, window.HWnd);
                Assert.AreEqual((uint)app.Process.Id, window.ProcessId);
                Assert.AreEqual(app.ExpectedWindow.Title, window.Title);
                Assert.AreNotEqual(IntPtr.Zero, window.IconHandle);
                Assert.IsNull(window.ProcessName);
            }
        }
Esempio n. 3
0
        private bool HideWindowIfNotForeground()
        {
            if (_mainWindowEntry?.IsForeground() ?? false)
            {
                return(false);
            }

#if (DEBUG)
            var foregroundWindow = WindowEntryFactory.Create(WindowToForeground.GetForegroundWindow());
            Log.DebugFormat("Window does not have focus when initialization is complete. Current foreground window is {0} (Process '{1}')", foregroundWindow.HWnd, foregroundWindow.ProcessName);
#endif

            Hide(false);
            return(true);
        }
Esempio n. 4
0
        public void Show()
        {
            lock (_lock)
            {
                if (_state == GoToWindowState.Shown)
                {
                    Log.Debug("Sending Tab Again to Main Window.");
                    _mainWindow.ShortcutAgain();
                    return;
                }

                if (_state != GoToWindowState.Hidden)
                {
                    return;
                }

                Log.Debug("Showing Main Window.");
                _state = GoToWindowState.Showing;
            }

            if (Showing != null)
            {
                Showing(this, new EventArgs());
            }

            SetAvailableWindowSize(SystemParameters.PrimaryScreenWidth, SystemParameters.PrimaryScreenHeight);
            _mainWindow.Left = SystemParameters.PrimaryScreenWidth / 2f - _mainViewModel.AvailableWindowWidth / 2f;
            _mainWindow.Top  = SystemParameters.PrimaryScreenHeight / 2f - (_mainViewModel.AvailableWindowHeight + 56) / 2f;
            _mainWindow.Show();

            if (_mainWindowEntry == null)
            {
                var interopHelper = new WindowInteropHelper(_mainWindow);
                _mainWindowEntry = WindowEntryFactory.Create(interopHelper.Handle);

                Log.DebugFormat("GoToWindow main window created with hWnd {0}", _mainWindowEntry.HWnd);
            }

            _mainWindow.SetFocus();
            _mainWindowEntry.Focus();

            Application.Current.Dispatcher.InvokeAsync(LoadViewModel, DispatcherPriority.Background);
        }
Esempio n. 5
0
        public void CanGiveFocusToAWindow()
        {
            using (var app1 = new GivenAnApp("GoToWindow.GetGetWindowEntry_FromTestWindow1"))
            {
                var window1 = WindowEntryFactory.Create(app1.Process.MainWindowHandle);

                using (var app2 = new GivenAnApp("GoToWindow.GetGetWindowEntry_FromTestWindow2"))
                {
                    var window2 = WindowEntryFactory.Create(app2.Process.MainWindowHandle);

                    Assert.IsFalse(window1.IsForeground());
                    Assert.IsTrue(window2.IsForeground());

                    window1.Focus();

                    Assert.IsTrue(window1.IsForeground());
                }
            }

            Assert.IsTrue(true, "This test just ensures the code doesn't crash");
        }
Esempio n. 6
0
        public void Show()
        {
            lock (_lock)
            {
                if (_mainWindow != null)
                {
                    Log.Debug("Sending Tab Again to Main Window.");
                    _mainWindow.ShortcutAgain();
                    return;
                }

                _mainViewModel = new MainViewModel();

                SetAvailableWindowSize(SystemParameters.PrimaryScreenWidth, SystemParameters.PrimaryScreenHeight);

                _mainWindow = new MainWindow {
                    DataContext = _mainViewModel
                };
                _mainWindow.Closing  += _mainWindow_Closing;
                _mainViewModel.Close += _mainViewModel_Close;

                Showing?.Invoke(this, new EventArgs());

                _mainWindow.Left  = SystemParameters.PrimaryScreenWidth / 2f - _mainViewModel.AvailableWindowWidth / 2f;
                _mainWindow.Top   = SystemParameters.PrimaryScreenHeight / 2f - (_mainViewModel.AvailableWindowHeight + 56) / 2f;
                _mainWindow.Width = _mainViewModel.AvailableWindowWidth;

                _mainWindow.Show();

                var interopHelper = new WindowInteropHelper(_mainWindow);
                _mainWindowEntry = WindowEntryFactory.Create(interopHelper.Handle);

                Log.DebugFormat("GoToWindow main window created with hWnd {0}", _mainWindowEntry.HWnd);

                _mainWindow.SetFocus();
                _mainWindowEntry.Focus();

                Application.Current.Dispatcher.InvokeAsync(LoadViewModel, DispatcherPriority.Input);
            }
        }