>> Declare Long GetExitCodeProcess in Kernel32 ; >> Long hProcess, Long @nExitCode >> >> ll_Error = (GetExitCodeProcess(ln_hProcess, @ln_ExitCode) == 0) >> If !ll_Error and (ln_ExitCode != 259) >> *** Do something >> endif >>>>
#Define STILL_ACTIVE 0x103 #Define STATUS_TIMEOUT 0x0102 #Define WAIT_TIMEOUT STATUS_TIMEOUT #Define WAIT_OBJECT_0 0 #Define SYNCHRONIZE 0x100000 Declare Long WaitForInputIdle in User32 ; Long hProcess, Long dwMilliseconds Declare Long GetWindowThreadProcessId in User32 ; Long nhWnd, Long @lpdwProcessId Declare Long OpenProcess in Kernel32 ; Long dwDesiredAccess, Long bInheritHandle, Long dwProcessId ln_Return = CreateProcess(...) ln_hProcess = ... ln_hThread = ... WaitForInputIdle( ln_hProcess, WAIT_TIMEOUT ) ln_ExitCode = STILL_ACTIVE ll_Error = .F. Do while ((ln_Return != WAIT_OBJECT_0) or (ln_ExitCode == STILL_ACTIVE)) and !ll_Error ln_Return = WaitForSingleObject(ln_hProcess, int(WAIT_TIMEOUT/3)) If (ln_Return == WAIT_OBJECT_0) ll_Error = (GetExitCodeProcess(ln_hProcess, @ln_ExitCode) == 0) If ll_Error ? 'Error: ', GetLastError() endif endif If (ln_Return == WAIT_OBJECT_0) and (ln_ExitCode == -1) and !ll_Error ** The process doesn't exit properly (probably killed / self terminated) ** Close the handle first CloseHandle( ln_hProcess ) CloseHandle( ln_hThread ) Store 0 to ln_hProcess, ln_hThread ** Search for the document we are trying to open lc_PDF = 'Acrobat Reader - [test.pdf]' ln_hWnd = FindWindow( Null, lc_PDF ) If (ln_hWnd != 0) ** It is opened by another process ** Get the process handle and start the loop again ln_ProcessId = 0 GetWindowThreadProcessId( ln_hWnd, @ln_ProcessId ) ln_hProcess = OpenProcess( SYNCHRONIZE, 0, ln_ProcessId ) If (ln_hProcess != 0) ln_Return = STATUS_TIMEOUT endif endif endif enddo If (ln_hProcess != 0) CloseHandle( ln_hProcess ) endif If (ln_hThread != 0) CloseHandle( ln_hThread ) endifBTW, is it ok to use this thread for this ?