只要记得先得到原来的文本就行了
下面是刚写的,向一个打开的文本文件里面输入文字(a.txt)
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
h: HWND;
str: pchar;
hEdit: HWND;
len: Integer;
text: String;
begin
if key=vk_return then
h := FindWindow(nil,pchar('a.txt - 记事本'));
if h > 0 then
begin
//Showmessage('found');
hEdit := FindWindowEx(h,0,'Edit',nil);
if hEdit > 0 then
begin
//先得到原来的文本
try
len := SendMessage(hEdit,WM_GETTEXTLENGTH,0,0);
Getmem(str,len+1);
SendMessage(hEdit,WM_GETTEXT,len+1,LPARAM(str));
//showmessage('found edit');
text := Strpas(str) + Edit1.Text;
SendMessage(hEdit,WM_SETTEXT,length(text),LPARAM(text));
finally
FreeMem(str);
end;
end;
end;
end;