示例#1
0
        private void getProcess(Window w)
        {
            if (w.Handle.ToInt32() == 0)
                return;
            uint pID;
            GetWindowThreadProcessId(w.Handle, out pID);
            Process proc = Process.GetProcessById(unchecked((int)pID));
            w.process = proc;
            w.pID = unchecked((int)pID);

        }
示例#2
0
        private List<Window> getAllWindows()
        {
            IntPtr shellWindow = GetShellWindow();
            Dictionary<IntPtr, Window> windows = new Dictionary<IntPtr, Window>();

            var watch = Stopwatch.StartNew();
            EnumWindows(delegate (IntPtr hWnd, int lParam)
            {

                Window t = new Window();

                if (!IsWindowVisible(hWnd)) return true;

                if (hWnd != shellWindow)
                {
                    int length = GetWindowTextLength(hWnd);
                    if (length == 0) return true;
                }
                StringBuilder sb = new StringBuilder(100);
                GetWindowText(hWnd, sb, sb.Capacity);

                t.Handle = hWnd;
                t.Title = sb.ToString();
                t.state = Window.OPEN;

                if (hWnd == shellWindow)
                {
                    t.Title = "Desktop";
                }
                if (!IsWindowVisible(hWnd))
                {
                    t.state = Window.INVISIBLE;
                }
                if (GetForegroundWindow() == hWnd)
                {
                    t.state = Window.FOREGROUND;
                }
                getProcess(t);

                windows[hWnd] = t;

                return true;

            }, 0);
            return windows.Values.ToList();
        }
示例#3
0
        public Window getForegroundWindow()
        {

            IntPtr shellWindow = GetShellWindow();
            IntPtr hwnd = GetForegroundWindow();
            Window t = new Window();
            if ((int)hwnd.ToInt32() > 0)
            {
                StringBuilder sb = new StringBuilder(100);
                GetWindowText(hwnd, sb, sb.Capacity);

                t.Handle = hwnd;

                if (hwnd == shellWindow)
                {
                    t.Title = "Desktop";
                }
                else
                {
                    t.Title = sb.ToString();

                }
                t.state = Window.FOREGROUND;

            }
            else
            {
                t.Handle = hwnd;
                t.Title = "";
                t.state = Window.INVISIBLE;

            }
            getProcess(t);
            List<Window> temp = new List<Window>();
            temp.Add(t);
            temp = ObtainFilenames(temp);


            return temp.First();
        }