Ejemplo n.º 1
0
		public GivenAnApp(string title)
		{
			_executable = GetResourcePath("GoToWindow.FakeApp.exe");
			const string processName = "GoToWindow.FakeApp";

			_process = new Process
			{
				StartInfo = new ProcessStartInfo
				{
					FileName = _executable,
					Arguments = "\"" + title + "\""
				}
			};

			if (!_process.Start())
				throw new Exception("Could not start fake app");

			Thread.Sleep(1000); //TODO: Instead wait for some console output

			ExpectedWindow = new WindowEntry
			{
				Title = title,
				ProcessId = (uint)_process.Id,
				ProcessName = processName,
				HWnd = _process.MainWindowHandle
			};
		}
Ejemplo n.º 2
0
        public GivenAnApp(string title)
        {
            Executable = GetResourcePath("GoToWindow.FakeApp.exe");
            const string processName = "GoToWindow.FakeApp";

            Process = new Process
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName  = Executable,
                    Arguments = "\"" + title + "\""
                }
            };

            if (!Process.Start())
            {
                throw new Exception("Could not start fake app");
            }

            Thread.Sleep(1000);             //TODO: Instead wait for some console output

            ExpectedWindow = new WindowEntry
            {
                Title       = title,
                ProcessId   = (uint)Process.Id,
                ProcessName = processName,
                HWnd        = Process.MainWindowHandle
            };
        }
Ejemplo n.º 3
0
        internal static void Del(TbHideWinEntry tag)
        {
            IWindowEntry entry = new WindowEntry();

            entry.ProcessName = tag.name;
            entry.Title       = tag.title;
            Del(entry);
        }
Ejemplo n.º 4
0
        public void resetData()
        {
            var isNeedRest = false;
            var wins       = WindowsListFactory.Load();

            // 如果为空则增加Empty提示
            if (wins.Windows.Count == 0)
            {
                IWindowEntry entry = new WindowEntry();
                entry.ProcessName = "Empty";
                wins.Windows.Add(entry);
            }
            // remove hide window
            if (mListHideWin.Count > 0)
            {
                for (int i = 0; i < wins.Windows.Count; i++)
                {
                    var win = wins.Windows.ElementAt(i);
                    for (int j = 0; j < mListHideWin.Count; j++)
                    {
                        if (win.ProcessName.Equals(mListHideWin.ElementAt(j).name) && win.Title.Equals(mListHideWin.ElementAt(j).title))
                        {
                            wins.Windows.RemoveAt(i--);
                            break;
                        }
                    }
                }
            }

            if (mWins == null)
            {
                isNeedRest = true;
                mWins      = wins;
                int i = 0;
                foreach (var win in wins.Windows)
                {
                    i++;
                    var btn = buildBtn(win, setElementWidth, setElementMargin);
                    stackPanel.Children.Add(btn);
                }
            }
            else
            {
                for (int i = 0; i < wins.Windows.Count; i++)
                {
                    var win = wins.Windows.ElementAt(i);
                    //Console.WriteLine(i + "   " + win.ProcessName);
                    int findIndex = -1;
                    for (int j = 0; j < mWins.Windows.Count; j++)
                    {
                        var mWin = mWins.Windows.ElementAt(j);
                        if (win.HWnd == mWin.HWnd)
                        {
                            findIndex = j;
                            break;
                        }
                    }
                    if (findIndex > -1)
                    {
                        // 需要交换位置
                        if (i != findIndex)
                        {
                            isNeedRest = true;
                            var first  = stackPanel.Children[i];
                            var second = stackPanel.Children[findIndex];
                            stackPanel.Children.Remove(first);
                            stackPanel.Children.Remove(second);
                            stackPanel.Children.Insert(i, second);
                            stackPanel.Children.Insert(findIndex, first);

                            var firstL  = mWins.Windows.ElementAt(i);
                            var secondL = mWins.Windows.ElementAt(findIndex);
                            mWins.Windows.Remove(firstL);
                            mWins.Windows.Remove(secondL);
                            mWins.Windows.Insert(i, secondL);
                            mWins.Windows.Insert(findIndex, firstL);
                        }
                    }
                    else
                    {
                        isNeedRest = true;
                        mWins.Windows.Insert(i, win);
                        stackPanel.Children.Insert(i, buildBtn(win, setElementWidth, setElementMargin));
                    }
                }
                // 去掉多余的
                while (mWins.Windows.Count > wins.Windows.Count)
                {
                    isNeedRest = true;
                    stackPanel.Children.RemoveAt(mWins.Windows.Count - 1);
                    mWins.Windows.RemoveAt(mWins.Windows.Count - 1);
                }
            }

            if (stackPanel.Children.Count > 0)
            {
                mFocusBtn = stackPanel.Children[stackPanel.Children.Count > 1 ? 1 : 0] as Button;
            }

            if (isNeedRest)
            {
                resetWindowSize();
            }
        }