Ejemplo n.º 1
0
        /// <summary>
        /// get the process that is the current foreground window
        /// </summary>
        /// <returns>the process of the foreground window</returns>
        public static Process GetForegroundProcess()
        {
            // get foreground process pointer
            IntPtr hWndForeground = LowLevel.GetForegroundWindow();

            // get PID for that pointer
            LowLevel.GetWindowThreadProcessId(hWndForeground, out uint fgPid);

            // get process by pid
            return(Process.GetProcessById((int)fgPid));
        }