var Form1: TForm1; cnt : Integer = 0; function EnumWindowsProc(Hwnd:THandle;lParam:LParam):boolean;Stdcall; function EnumChildProc(Hwnd:THandle;lParam:LParam):boolean;Stdcall;implementation{$R *.DFM}function EnumWindowsProc(Hwnd:THandle;lParam:LParam):boolean; var WindowCaption:array[0..254] of Char; begin GetWindowText(Hwnd,WindowCaption,255); if StrPas(WindowCaption)=Form1.Edit1.Text then begin cnt := 0; EnumChildWindows(Hwnd,@EnumChildProc,0); Result := False; Exit; end; Result := True; end;function EnumChildProc(Hwnd:THandle;lParam:LParam):boolean; var WindowCaption,WindowClass:array[0..254] of Char; begin GetClassName(Hwnd,WindowClass,255); if Pos('EDIT',UpperCase(StrPas(WindowClass))) > 0 then begin Inc(cnt); SendMessage(Hwnd,WM_SETTEXT,0,LongInt(PChar(IntToStr(cnt)))); ////此处换成SendMessage(Hwnd,WM_SETTEXT,0,LongInt(PChar('你想送的字符串')));即可 end; Result := True; end;procedure TForm1.Button1Click(Sender: TObject); begin Enumwindows(@EnumWindowsProc,0); end;
也可以这样,不同的只是查找这个EDIT句柄,发送都是一样的方法: var h,e:HWND;begin h:=FindWindow(nil,'TForm1'); e:=FindWindowEx(h,0,'TEdit',nil); SendMessage(e,WM_SETTEXT,0,LongInt(PChar(IntToStr(cnt)))); ////此处换成SendMessage(e,WM_SETTEXT,0,LongInt(PChar('你想送的字符串'))); end;
Form1: TForm1;
cnt : Integer = 0;
function EnumWindowsProc(Hwnd:THandle;lParam:LParam):boolean;Stdcall;
function EnumChildProc(Hwnd:THandle;lParam:LParam):boolean;Stdcall;implementation{$R *.DFM}function EnumWindowsProc(Hwnd:THandle;lParam:LParam):boolean;
var
WindowCaption:array[0..254] of Char;
begin
GetWindowText(Hwnd,WindowCaption,255);
if StrPas(WindowCaption)=Form1.Edit1.Text then
begin
cnt := 0;
EnumChildWindows(Hwnd,@EnumChildProc,0);
Result := False;
Exit;
end;
Result := True;
end;function EnumChildProc(Hwnd:THandle;lParam:LParam):boolean;
var
WindowCaption,WindowClass:array[0..254] of Char;
begin
GetClassName(Hwnd,WindowClass,255);
if Pos('EDIT',UpperCase(StrPas(WindowClass))) > 0 then
begin
Inc(cnt);
SendMessage(Hwnd,WM_SETTEXT,0,LongInt(PChar(IntToStr(cnt))));
////此处换成SendMessage(Hwnd,WM_SETTEXT,0,LongInt(PChar('你想送的字符串')));即可
end;
Result := True;
end;procedure TForm1.Button1Click(Sender: TObject);
begin
Enumwindows(@EnumWindowsProc,0);
end;
var
h,e:HWND;begin
h:=FindWindow(nil,'TForm1');
e:=FindWindowEx(h,0,'TEdit',nil);
SendMessage(e,WM_SETTEXT,0,LongInt(PChar(IntToStr(cnt))));
////此处换成SendMessage(e,WM_SETTEXT,0,LongInt(PChar('你想送的字符串')));
end;