Esempio n. 1
0
        // Returns the name of the process owning the foreground window.
        public static Process GetForegroundProcess()
        {
            IntPtr hwnd = NativeWin32.GetForegroundWindow();

            // The foreground window can be NULL in certain circumstances,
            // such as when a window is losing activation.
            if (hwnd == null || hwnd == IntPtr.Zero)
            {
                return(null);
            }

            uint pid;

            NativeWin32.GetWindowThreadProcessId(hwnd, out pid);

            return(Process.GetProcesses().FirstOrDefault(p => p.Id == pid));
        }