>I have an application that starts another task doing a Run /N xxx.exe. The problem I am having is the new task keeps focus while
>the original task seems to run in the background. What I want to do is cause the original task to be the active task as quickly
>as possible after the second task is started. I have a routine that I have tried using the sendmessage command along with a
>messagereceived event. I coded a setfocus in the event but that did not work. A C programmer friend of mine said to try the
>windows setfocus command but in order to do that I need to know what my window handle is. Any ideas?
Rather than using RUN, use my API_APPRUN class; it will return a thread id and thread handle for the new application, and allow you to run it either synchronously or asynchronously, and determine when it terminates. If you have a thread handle, you can issue a Windows message to the main window of the new process via PostMessageToThread(), using the thread ID to specify the target of the message, which it then routes to it's primary hWnd. It also lets you specify the startup Window mode for the new executable.
You'd do something like:
SET CLASSLIB TO Process ADDITIVE
oAPP = CREATEONJ('API_APPRUN','MyExeToRun with parameters','C:\MyApp\ShouldRunHere','MAX')
oApp.LaunchApp()
nMyAppThreadID = oApp.GetThreadId()
DECLARE SHORT PostThreadMessage IN USER32 ;
INTEGER idThread, ;
INTEGER Msg, ;
INTEGER wParam, ;
INTEGER lParam
DECLARE INTEGER GetActiveWindow IN WIN32API
=PostThreadMessage(nMyAppThreadID, WM_SHOWWINDOW, WA_ACTIVATE, GetActiveWindow())
You'll need to look up the values of WM_ACTIVATE and WA_ACTIVE in the MSDN docs or WINUSER.H