El unico problema es que la funcion GetWindowText no devuelve el texto de otras aplicaciones que no sean la tuya. Para hacer eso se puede usar el mensage WM_GETTEXT que permite obtener el texto de otras ventanas.
Aqui te dejo un ejemplo que obtiene el texto de todas las ventanas que encuentra y lo escribe en un memo.
Código:
function EnumChildProc(handle: Thandle; Param: lParam): boolean; stdcall;
var
Buffer: PChar;
l: integer;
begin
result:= TRUE;
l:= sendmessage(handle,WM_GETTEXTLENGTH,0,0);
if l > 0 then
begin
GetMem(Buffer, l+1);
try
sendmessage(handle,WM_GETTEXT,l+1,lParam(buffer));
form1.Memo1.Lines.Add(string(buffer));
finally
FreeMem(Buffer);
end;
end;
end;
function EnumWindowsProc(handle: Thandle; Param: lParam): boolean; stdcall;
begin
result:= TRUE;
EnumChildWindows(handle,@EnumChildProc,0);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
EnumWindows(@EnumWindowsProc,0);
end;