帮你找的 向其他窗口中的EDIT发送字符串!unit Umain; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Spin, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Label1: TLabel; Edit1: TEdit; Label2: TLabel; SpinEdit1: TSpinEdit; Label3: TLabel; Edit2: TEdit; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; 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; end.
向其他窗口中的EDIT发送字符串!unit Umain; interface uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Spin, StdCtrls; type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
SpinEdit1: TSpinEdit;
Label3: TLabel;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; 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; end.