I wrote an application starter (starts other programs using RunProgram).
I wanted to include a feature that all opened applications will ber closed when closing the launcher.
The only way I found is the following (using the windowhandle)
The procedure starting a program:
Code: Select all
Procedure RunProgramEx(filename$,parameter$,directory$)
If Left(parameter$,1)<>" "
parameter$=" "+parameter$
EndIf
Info.STARTUPINFO
Info\cb=SizeOf(STARTUPINFO)
Info\dwFlags=1
Info\wShowWindow=#SW_SHOWNORMAL
ProcessInfo.PROCESS_INFORMATION
If UCase(GetExtensionPart(filename$))="EXE"
If CreateProcess_(@filename$,@parameter$,0,0,0,#NORMAL_PRIORITY_CLASS ,0,@directory$,@Info,@ProcessInfo)
ProcessID=ProcessInfo\dwProcessId
Delay(100)
WaitForInputIdle_(ProcessInfo\hProcess, 30000) ;wait for application to accept input, wait maximum 30 seconds
count = 0
Repeat
Delay(100) ;avoid hanging of windows during start of application while searching for the window
count=count + 1 ;security counter to avoid hanging
win=FindWindow_(0,0)
While win<>0
GetWindowThreadProcessId_(win,@pid.l)
If pid=ProcessID
If GetParent_(win)=0 ;save handle only if not a child window
WinHandle=win
Break
EndIf
EndIf
win=GetWindow_(win,#GW_HWNDNEXT) ;check next window
Wend
Until WinHandle Or (count=100) ;wait up to 10 seconds for window to occur
EndIf
Else
RunProgram(filename$,parameter$,directory$)
WinHandle = 0 ;just for security
EndIf
ProcedureReturn WinHandle
EndProcedure
For closing the started application I do:
Code: Select all
PostMessage_(WinHandle,#WM_CLOSE,0,0); close Window
Is anyone aware of some other possibility? Any ideas.
Thanks a million.