Example #1
0
        private void UpdatePPWindowList()
        {
            List <Process> ppProcesses = new List <Process>();

            // Find puzzle pirates windows

            // Make a guess for the process name
            Process[] processes = Process.GetProcessesByName("javaw");
            foreach (Process p in processes)
            {
                if (p.MainWindowTitle.Contains("Puzzle Pirates -"))
                {
                    ppProcesses.Add(p);
                }
            }

            if (ppProcesses.Count <= 0)
            {
                // Guess was wrong so go looking by main window title only
                foreach (Process p in Process.GetProcesses())
                {
                    if (p != null && p.MainWindowTitle.Contains("Puzzle Pirates -"))
                    {
                        ppProcesses.Add(p);
                    }
                }
            }

            ProcessWrapper lastSelected = null;

            if (comboBoxPPWindows.Items.Count > 0)
            {
                lastSelected = comboBoxPPWindows.SelectedItem as ProcessWrapper;
            }

            comboBoxPPWindows.Items.Clear();
            foreach (Process p in ppProcesses)
            {
                comboBoxPPWindows.Items.Add(new ProcessWrapper(p));
            }
            if (comboBoxPPWindows.Items.Count > 0)
            {
                // Retain previous selection if possible, otherwise set to first item
                comboBoxPPWindows.SelectedIndex = 0;
                if (lastSelected != null)
                {
                    ProcessWrapper p;
                    for (int i = 0; i < comboBoxPPWindows.Items.Count; i++)
                    {
                        p = comboBoxPPWindows.Items[i] as ProcessWrapper;
                        if (p != null && p.ToString().Equals(lastSelected.ToString()))
                        {
                            comboBoxPPWindows.SelectedIndex = i;
                            break;
                        }
                    }
                }
            }
        }