when I open a calculator (calc.exe) in main window, I want to bring to front it
and I want to kill this calculator when I close the main window.
Does RunProgram retrieve ThreadID ?
Re: Does RunProgram retrieve ThreadID ?
See Thorsten's tip at viewtopic.php?t=6442
I don't why this solution does not work...
Code: Select all
hProcess=RunProgram(GetSystemDir()+"\calc.exe")
app=GetRunProgramHandle(hProcess)
ShowWindow_(app, #SW_MINIMIZE)Code: Select all
Procedure.l GetRunProgramHandle(hProcessProgram.l)
win = FindWindow_(0,0)
While win<>0 And quit=0
If GetParent_(win)=WindowID()
GetWindowThreadProcessId_(win, @pid.l)
hProcess=OpenProcess_(#PROCESS_CREATE_PROCESS,0,pid)
If hProcess = hProcessProgram
app=win
quit=1
EndIf
EndIf
win = GetWindow_(win, #GW_HWNDNEXT)
Wend
ProcedureReturn app
EndProcedure
Try this one:
This Runprogram2 procedure returns the handle to the new opened
window, if possible.
You have to specify both, full path to exe, and full working directory path
to make sure it works correct on all windows versions.
btw: The ProcessInfo Structure which is filled up with information by
OpenProcess contains ProcessID, ThreadID, ProcessHandle and
ThreadHandle of the new process (just in case you need it)
Timo
Code: Select all
Procedure.l EnumWindowsProc(hWnd.l, lParam.l)
Shared RunProgram_WindowID.l
If GetWindowThreadProcessId_(hWnd, 0) = lParam
RunProgram_WindowID = hWnd
ProcedureReturn #FALSE
Else
ProcedureReturn #TRUE
EndIf
EndProcedure
Procedure.l RunProgram2(Filename.s, Parameter.s, Directory.s)
Shared RunProgram_WindowID.l
Info.STARTUPINFO
Info\cb = SizeOf(STARTUPINFO)
Debug CreateProcess_(@Filename, @Parameter, 0, 0, 0, 0, 0, @Directory, @Info, @ProcessInfo.PROCESS_INFORMATION)
Debug getlasterror_()
RunProgram_WindowID = 0
EnumWindows_(@EnumWindowsProc(), ProcessInfo\dwThreadId)
ProcedureReturn RunProgram_WindowID
EndProcedure
Debug RunProgram2("C:\WINNT\notepad.exe","","C:\WINNT\")
Debug FindWindow_(0, "Untitled - Notepad")
End
window, if possible.
You have to specify both, full path to exe, and full working directory path
to make sure it works correct on all windows versions.
btw: The ProcessInfo Structure which is filled up with information by
OpenProcess contains ProcessID, ThreadID, ProcessHandle and
ThreadHandle of the new process (just in case you need it)
Timo
quidquid Latine dictum sit altum videtur

