Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Capture Text from another non-Delphi application window

102 views
Skip to first unread message

Matt Nielsen

unread,
Dec 12, 2002, 10:46:29 AM12/12/02
to
I have a need to capture the text from a scrolling text window in another
program that I don't have access to only through a window handle. Can I use
SendMEssage or something to ge the text with WM_GETTEXT type message. I
know there are programs like spell checkers that can do this. Any help
would be appreciated.

Thanks,

Matt


Jason

unread,
Dec 12, 2002, 12:06:28 PM12/12/02
to
This might be helpful to you.


{
The example runs 'chkdsk.exe c:\' and displays the output to Memo1

Put a TMemo (Memo1) and a TButton (Button1) in your form
Put this code in the OnCLick of Button1:
}

procedure TForm1.Button1Click(Sender: TObject);

procedure RunDosInMemo(DosApp:String;AMemo:TMemo);
const
ReadBuffer = 2400;
var
Security : TSecurityAttributes;
ReadPipe,WritePipe : THandle;
start : TStartUpInfo;
ProcessInfo : TProcessInformation;
Buffer : Pchar;
BytesRead : DWord;
Apprunning : DWord;
begin
With Security do begin
nlength := SizeOf(TSecurityAttributes);
binherithandle := true;
lpsecuritydescriptor := nil;
end;
if Createpipe (ReadPipe, WritePipe,
@Security, 0) then begin
Buffer := AllocMem(ReadBuffer + 1);
FillChar(Start,Sizeof(Start),#0);
start.cb := SizeOf(start);
start.hStdOutput := WritePipe;
start.hStdInput := ReadPipe;
start.dwFlags := STARTF_USESTDHANDLES +
STARTF_USESHOWWINDOW;
start.wShowWindow := SW_HIDE;

if CreateProcess(nil,
PChar(DosApp),
@Security,
@Security,
true,
NORMAL_PRIORITY_CLASS,
nil,
nil,
start,
ProcessInfo)
then
begin
repeat
Apprunning := WaitForSingleObject
(ProcessInfo.hProcess,100);
Application.ProcessMessages;
until (Apprunning <> WAIT_TIMEOUT);
Repeat
BytesRead := 0;
ReadFile(ReadPipe,Buffer[0],
ReadBuffer,BytesRead,nil);
Buffer[BytesRead]:= #0;
OemToAnsi(Buffer,Buffer);
AMemo.Text := AMemo.text + String(Buffer);
until (BytesRead < ReadBuffer);
end;
FreeMem(Buffer);
CloseHandle(ProcessInfo.hProcess);
CloseHandle(ProcessInfo.hThread);
CloseHandle(ReadPipe);
CloseHandle(WritePipe);
end;
end;

begin {button 1 code}
RunDosInMemo('chkdsk.exe c:\',Memo1);
end;


"Matt Nielsen" <mnie...@caelix.com> wrote in message
news:3df8af41$1...@newsgroups.borland.com...

Matt Nielsen

unread,
Dec 12, 2002, 12:10:47 PM12/12/02
to
Unfourtunaly that will only work with app that send output to stdout. A
windows app usually doesn't do this.

I want to be able to point to a window retrieve the window handle and verify
that the window is of a given class(RichText type) and then extract the text
contained in the window to my local variable.

Matt

"Jason" <in...@goff.nu> wrote in message
news:3df8c1cb$1...@newsgroups.borland.com...

0 new messages