你试试看:
var cnt:integer;
function GetEditHandle(HWND: Integer; lparam: Longint): BooLean; stdcall;
var
buffer: array[0..255] of Char;
buffer1: array[0..255] of Char;
i:integer;
begin
i:=0;
Result := True;
//得到目标窗口的控件
GetClassName(HWND, buffer, 256);
//找到发消息的目标窗口的目标控件
if StrPas(buffer) = 'EDIT' then
begin
inc(i);
if i=cnt then
begin
GetWindowText(HWND, buffer1, 100);
PInteger(lparam)^ := HWND; //得到目标控件的Hwnd(句柄)
Result := False; //终止循环
end;
end;
end; //end of function
procedure TForm1.Button3Click(Sender: TObject);
var TxtHandle: Integer;
begin
cnt:=1; //第一个edit
TxtHandle := 0;
//取消息输入框的,FTextHandle
EnumChildWindows(TxtHandle, @GetEditHandle, Integer(@TxtHandle));
FTextHandle := TxtHandle;
SendMessage(FTextHandle, WM_SETTEXT, 0, Integer(pchar(Memo2.Text)));
cnt:=2; //第二个edit
EnumChildWindows(TxtHandle, @GetEditHandle, Integer(@TxtHandle));
FTextHandle := TxtHandle;
SendMessage(FTextHandle, WM_SETTEXT, 0, Integer(pchar(Memo2.Text)));
end;