Extend RunProgram : retrieve handle of opened window
Posted: Sat Jun 28, 2003 8:21 pm
Code updated for 5.20+
Example :
Program :
Tip BrainStorming : viewtopic.php?p=29189#29189
Special Thanks to Freak & PB

Example :
Code: Select all
; /////////////////////////////
; System Directory
; /////////////////////////////
Procedure.s GetSystemDir()
systemdir$=Space(255)
lg = GetSystemDirectory_(systemdir$, 255)
systemdir$=Left(systemdir$,lg)
ProcedureReturn systemdir$
EndProcedure
command$=GetSystemDir()+"\calc.exe"
app=RunProgramEx(command$,"",GetPathPart(command$), #SW_NORMAL)
ShowWindow_(app, #SW_MINIMIZE)
Code: Select all
; ///////////////////////
; Run Program Ex
; ///////////////////////
Procedure RunProgramEx(Filename.s, Parameter.s, Directory.s, ShowFlag)
Info.STARTUPINFO
Info\cb =SizeOf(STARTUPINFO)
Info\dwFlags =1 ;#STARTF_USESHOWWINDOW
Info\wShowWindow =ShowFlag
ProcessInfo.PROCESS_INFORMATION
ProcessPriority=$20 ;NORMAL_PRIORITY
;Create a window and retrieve its process
If CreateProcess_(@Filename, @Parameter, 0, 0, 0, ProcessPriority, 0, @Directory, @Info, @ProcessInfo)
;Process Values
ProcessID =ProcessInfo\dwProcessId
;Find Window Handle of Process
Repeat
win=FindWindow_(0,0)
While win<>0 And quit=0
GetWindowThreadProcessId_(win, @pid)
If pid=ProcessID
WinHandle=win
quit=1
EndIf
win=GetWindow_(win, #GW_HWNDNEXT)
Wend
Until WinHandle
EndIf
;Retrieve Window Handle
ProcedureReturn WinHandle
EndProcedure
Special Thanks to Freak & PB

