コード例 #1
0
        private void HotkeyPressed(int direction)
        {
            var activated = WinAPI.ApplicationIsActivated(Process.GetCurrentProcess().Id);

            Console.WriteLine("Window activated? {0}.", activated);

            // If the window is not already visible:
            // - make it visble/foregrounded
            // - ensure the **second** item in the list (index = 1) is selected
            if (!activated)
            {
                this.Show();
                this.Activate();

                lbTodoList.SelectedIndex = 1;
            }
            // If the window is already visible:
            // - Move to next item in list
            // - Or, if at last item, wrap back round to the first item
            else
            {
                if (lbTodoList.SelectedIndex == lbTodoList.Items.Count - 1)
                {
                    lbTodoList.SelectedIndex = 0;
                }
                else
                {
                    lbTodoList.SelectedIndex = lbTodoList.SelectedIndex + direction;
                }
            }
        }
コード例 #2
0
        public static IList <DesktopWindow> GetAll()
        {
            var processes       = System.Diagnostics.Process.GetProcesses();
            var usefulProcesses = processes.Where(x => x.MainWindowHandle != IntPtr.Zero && !x.ProcessName.EndsWith("Host"));//.Select(x => GetRealProcess(x)).GroupBy(x => x.ProcessName);

            _all = usefulProcesses.Select(proc => new DesktopWindow {
                Name = proc.ProcessName, ProcessId = proc.MainWindowHandle, IsForeground = WinAPI.ApplicationIsActivated(proc.Id)
            }).ToList();

            return(_all);
        }