static private bool ChildWindowCallback(IntPtr hwnd, IntPtr lparam) { var process = Process.GetProcessById(WinAPIFunctions.GetWindowProcessId(hwnd)); if (process.ProcessName != "ApplicationFrameHost") { _realProcess = process; } return(true); }
static public Process Find() { var foregroundProcess = Process.GetProcessById(WinAPIFunctions.GetWindowProcessId(WinAPIFunctions.GetforegroundWindow())); if (foregroundProcess.ProcessName == "ApplicationFrameHost") { foregroundProcess = GetRealProcess(foregroundProcess); } return(foregroundProcess); }
static private Process GetRealProcess(Process foregroundProcess) { WinAPIFunctions.EnumChildWindows(foregroundProcess.MainWindowHandle, ChildWindowCallback, IntPtr.Zero); return(_realProcess); }