unit FrmUnit;<br><br>interface<br><br>uses<br> Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,<br> Dialogs, StdCtrls, CheckLst, ExtCtrls, ComCtrls;<br><br>type<br> TSendFrm = class(TForm)<br> SendBtn: TButton;<br> Label1: TLabel;<br> Memo1: TMemo;<br> Label2: TLabel;<br> Memo2: TMemo;<br> Label3: TLabel;<br> Edit1: TEdit;<br> Label4: TLabel;<br> Edit2: TEdit;<br> procedure SendBtnClick(Sender: TObject);<br> procedure FormClose(Sender: TObject; var Action: TCloseAction);<br> procedure FormCreate(Sender: TObject);<br> end;<br><br>var<br> SendFrm: TSendFrm;<br> NeedLoop: Bool = FALSE;<br><br>implementation<br><br>{$R *.dfm}<br><br>procedure LoopStop(TimeOut: DWORD);<br>var<br> StartTick: DWORD;<br>begin<br> StartTick := GetTickCount();<br> repeat<br> Application.ProcessMessages;<br> Sleep(1);<br> until (GetTickCount() - StartTick > TimeOut) or (not NeedLoop);<br>end;<br><br>procedure SendText(hWnd: HWND; Text: string);<br>var<br> hDialog, hButton, hAfxWnd42, hRICHEDIT: DWORD;<br> J: Integer;<br>begin<br> hDialog := FindWindowEx(hWnd, 0, '#32770', nil);<br> if (hDialog = 0) then Exit;<br><br> hButton := FindWindowEx(hDialog, 0, 'Button', '发送(&S)');<br> if (hButton = 0) then Exit;<br><br> hAfxWnd42 := 0;<br> repeat<br> hAfxWnd42 := FindWindowEx(hDialog, hAfxWnd42, 'AfxWnd42', nil);<br> if (hAfxWnd42 = 0) then Exit;<br><br> hRICHEDIT := FindWindowEx(hAfxWnd42, 0, 'RICHEDIT', nil);<br> until (hRICHEDIT <> 0);<br><br> J := 1;<br> while (J <= StrToInt(SendFrm.Edit1.Text)) and (NeedLoop) do<br> begin<br> SendMessage(hRICHEDIT, EM_REPLACESEL, 0, Integer(@Text[1]));<br> SendMessage(hButton, BM_CLICK, 0 , 0);<br> J := J + 1;<br> LoopStop(StrToInt(SendFrm.Edit2.Text) * 1000);<br> end;<br>end;<br><br>function EnumFunc(hWnd: HWND; lParam: LPARAM): BOOL; stdcall;<br>var<br> Buffer: array[0..50] of Char;<br> J: Integer;<br>begin<br> Result := NeedLoop;<br><br> Buffer[GetWindowText(hWnd, Buffer, 50)] := #0;<br><br> if (SendFrm.Memo2.Lines.Count = 0) then<br> begin<br> if (Pos('聊天中', Buffer) > 0) then SendText(hWnd, SendFrm.Memo1.Text);<br> end else<br> begin<br> for J := 0 to SendFrm.Memo2.Lines.Count do<br> if (Buffer = '与 ' + Trim(SendFrm.Memo2.Lines.Strings[J]) + ' 聊天中') then<br> SendText(hWnd, SendFrm.Memo1.Text);<br> end; <br>end;<br><br>procedure TSendFrm.SendBtnClick(Sender: TObject);<br>begin<br> if (SendBtn.Caption = '发送') then<br> begin<br> SendBtn.Caption := '停止';<br> NeedLoop := TRUE;<br> EnumWindows(@EnumFunc, 0);<br> SendBtn.Caption := '发送';<br> end else<br> begin<br> NeedLoop := FALSE;<br> end;<br>end;<br><br>procedure TSendFrm.FormClose(Sender: TObject; var Action: TCloseAction);<br>begin<br> NeedLoop := FALSE;<br>end;<br><br>procedure TSendFrm.FormCreate(Sender: TObject);<br>begin<br> SetWindowLong(Edit1.Handle, GWL_STYLE, GetWindowLong(Edit1.Handle, GWL_STYLE) or ES_NUMBER);<br> SetWindowLong(Edit2.Handle, GWL_STYLE, GetWindowLong(Edit2.Handle, GWL_STYLE) or ES_NUMBER);<br>end;<br><br>end.