示例#1
0
        /// <summary>
        /// The child window callback.
        /// </summary>
        /// <param name="hwnd">
        /// The hwnd.
        /// </param>
        /// <param name="lparam">
        /// The lparam.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private bool ChildWindowCallback(IntPtr hwnd, IntPtr lparam)
        {
            var process = Process.GetProcessById(WindowsApiFunctions.GetWindowProcessId(hwnd));

            if (process.ProcessName != "ApplicationFrameHost")
            {
                this.realProcess = process;
            }
            return(true);
        }
示例#2
0
        /// <summary>
        /// The get foreground app.
        /// </summary>
        /// <returns>
        /// The <see cref="string"/>.
        /// </returns>
        public string GetForegroundApp()
        {
            var foregroundProcess = Process.GetProcessById(WindowsApiFunctions.GetWindowProcessId(WindowsApiFunctions.GetforegroundWindow()));

            if (foregroundProcess.ProcessName == "ApplicationFrameHost")
            {
                foregroundProcess = this.GetRealProcess(foregroundProcess);
            }
            if (foregroundProcess == null)
            {
                return(this.GetForegroundApp());
            }
            else
            {
                return(foregroundProcess.ProcessName);
            }
        }
示例#3
0
 /// <summary>
 /// The get real process.
 /// </summary>
 /// <param name="foregroundProcess">
 /// The foreground process.
 /// </param>
 /// <returns>
 /// The <see cref="Process"/>.
 /// </returns>
 private Process GetRealProcess(Process foregroundProcess)
 {
     WindowsApiFunctions.EnumChildWindows(foregroundProcess.MainWindowHandle, this.ChildWindowCallback, IntPtr.Zero);
     return(this.realProcess);
 }