Extended version without global, without delay and immediate response:
Code: Select all
EnableExplicit
Structure RunProgramExtendedStructure
ProgramID.i
WindowHandle.i
EndStructure
Procedure.i EnumWindowsCallBack(hwnd.i, param.i)
Protected Result.i, PID.l, Length.i, *RunProgramExtended.RunProgramExtendedStructure
Result = #True
*RunProgramExtended = param
If GetWindowThreadProcessId_(hwnd, @PID)
If PID = *RunProgramExtended\ProgramID
*RunProgramExtended\WindowHandle = hwnd
Result = #False
EndIf
EndIf
ProcedureReturn Result
EndProcedure
Define Compiler.i, *Buffer, Length.i, Title$, NewTitle$
Define RunProgramExtended.RunProgramExtendedStructure
Compiler = RunProgram("cmd","","", #PB_Program_Open | #PB_Program_Read)
If Compiler
*Buffer = AllocateMemory(#MAX_PATH * SizeOf(Character), #PB_Memory_NoClear)
If *Buffer
RunProgramExtended\ProgramID = ProgramID(Compiler)
While ProgramRunning(Compiler)
If RunProgramExtended\WindowHandle = 0
EnumWindows_(@EnumWindowsCallBack(), @RunProgramExtended)
Else
Length = GetWindowText_(RunProgramExtended\WindowHandle, *Buffer, #MAX_PATH)
If Length
;Debug Length
NewTitle$ = PeekS(*Buffer, Length)
If Title$ <> NewTitle$
Title$ = NewTitle$
Debug "Title: " + Title$
EndIf
EndIf
EndIf
Length = AvailableProgramOutput(Compiler)
If Length
If ReadProgramData(Compiler,*Buffer, Length)
Debug PeekS(*Buffer, Length, #PB_UTF8|#PB_ByteLength)
EndIf
EndIf
Wend
FreeMemory(*Buffer)
EndIf
CloseProgram(Compiler) ; Close the connection to the program
EndIf
You can click with left/right mousebutton inside the window to see the changing title.