FUNCTION x_payrun LPARAMETERS p_title LOCAL llThread IF EMPTY(p_title) RETURN -1 ENDIF llThread = .F. IF TYPE("p_thread") = "N" llThread = .T. ENDIF #DEFINE GW_HWNDLAST 1 #DEFINE GW_HWNDNEXT 2 #DEFINE GW_CHILD 5 DO decl LOCAL hDesktop, hFirstChild, hLastChild, rc, cWinCap, cWinClass,; nVisible, nLeft, nTop, nRight, nBottom hDesktop = GetDesktopWindow() hFirstChild = GetWindow(hDesktop, GW_CHILD) hLastChild = GetWindow(hFirstChild, GW_HWNDLAST) hCurrent = hFirstChild DO WHILE .T. cWinCap = GetWinText(hCurrent) IF (UPPER(ALLTRIM(p_title))$UPPER(ALLTRIM(cWinCap))) and IsWindowVisible(hCurrent) <> 0 * got the correct window llReturn = hCurrent IF llThread IF hCurrent = p_thread * window is still open keep solus waiting before shutting down RETURN hCurrent ELSE RETURN -1 ENDIF ELSE * if we find it activate it before closing it Declare Integer ShowWindow in Win32API ; Integer hwnd, Integer nCmdShow * Restore it to its last size and position = ShowWindow(hCurrent,9) EXIT ENDIF ENDIF IF hCurrent = hLastChild llReturn = -1 EXIT ENDIF hCurrent = GetWindow(hCurrent, GW_HWNDNEXT) ENDDO RETURN llReturnThis bit uses the thread to send a message to the exe to close
LPARAMETERS lctitle LOCAL lnRet IF EMPTY(lcTitle) RETURN ENDIF lnhWnd = x_payrun(lctitle) IF lnhWnd > 0 #DEFINE WM_CLOSE 0x0010 DECLARE INTEGER SendMessage IN Win32API; INTEGER hwnd, INTEGER uMsg, ; INTEGER wParam, INTEGER lParam DECLARE INTEGER GetLastError IN kernel32 DECLARE INTEGER CloseHandle IN kernel32 INTEGER hObject * lnhWnd is the Window handle to close * Close and allow prompt to save changes lnRet=SendMessage(lnhWnd, WM_CLOSE, 0, 0) DO WHILE x_payrun(lctitle,lnhWnd) > 0 * loop solus IF INKEY() = 27 * escape pressed - loop over this session EXIT ENDIF ENDDO * Unable to communicate IF lnRet <> 0 =MESSAGEBOX("Error occurred. Error code: "+STR(getlasterror()),16,"Solus Application Error" ) RETURN ELSE =CloseHandle(lnhWnd) ENDIF ENDIFHope this makes sense (and works).