From 9fc973926aaa0c116643ace3f9a354593b9fad10 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sun, 27 Sep 2020 00:53:14 +0200 Subject: [PATCH] Re-incorporate the WaitForInputIdle() function, because MSDN says: "For example, the parent process should use the WaitForInputIdle function before trying to find a window associated with the child process." --- src/head.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/head.c b/src/head.c index f84e6c0..313ce6e 100644 --- a/src/head.c +++ b/src/head.c @@ -323,16 +323,21 @@ static BOOL signaled_or_failed(const DWORD wait_result) static BOOL wait_for_process_ready(const HWND hwnd, const HANDLE process_handle, const DWORD process_id) { + BOOL input_idle = FALSE; const DWORD ticks_start = GetTickCount(); for (;;) { - const HWND child_hwnd = find_window_by_process_id(process_id); - if (child_hwnd) + if (input_idle || signaled_or_failed(WaitForInputIdle(process_handle, 125U))) { - SwitchToThisWindow(child_hwnd, TRUE); - return TRUE; + const HWND child_hwnd = find_window_by_process_id(process_id); + if (child_hwnd) + { + SwitchToThisWindow(child_hwnd, TRUE); + return TRUE; + } + input_idle = TRUE; } - if (signaled_or_failed(WaitForSingleObject(process_handle, 13U))) + if (signaled_or_failed(WaitForSingleObject(process_handle, 1U))) { break; }