unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) ListBox1: TListBox; Button1: TButton; Button2: TButton; Edit1: TEdit; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} function GetAllHandle(hwnd: Integer; lparam: Longint): Boolean; stdcall; //回调函数 var buffer: array[0..255] of Char; s: string; int: integer; begin Result := True; GetClassName(hwnd, buffer, 256); Form1.listbox1.items.add(format('%d', [hwnd, StrPas(Buffer)])); //写入窗口ListBox1中 end; procedure TForm1.Button1Click(Sender: TObject); var handle: THandle; begin Handle := findWindow(nil, Pchar('Borland Delphi 7 Enterprise Edition - Installation Wizard')); //获得句柄 if Handle <> 0 then begin EnumChildWindows(Handle, @GetAllHandle, Integer(@Handle)); // 枚举子窗体 if Form1.ListBox1.Items.Count = 30 then //这是破解delphi7的代码片段,由Timer控制这段代码运行,由于Delphi7安装时打开的窗口比较多,这里对窗口作一个简单的分析,判断要写入注册码的窗口内的控件句柄是否为31个(0——30) begin handle := StrToInt(Trim(Form1.ListBox1.Items.Strings[3])); //给delphi7输入注册码 SendMessage(handle, WM_SETTEXT, 255, Integer(PChar('6KN6'))); handle := StrToInt(Trim(Form1.ListBox1.Items.Strings[5])); SendMessage(handle, WM_SETTEXT, 255, Integer(PChar('PNWBQS'))); handle := StrToInt(Trim(Form1.ListBox1.Items.Strings[7])); SendMessage(handle, WM_SETTEXT, 255, Integer(PChar('PB?ZUB'))); handle := StrToInt(Trim(Form1.ListBox1.Items.Strings[9])); SendMessage(handle, WM_SETTEXT, 255, Integer(PChar('J8XW'))); handle := StrToInt(Trim(Form1.ListBox1.Items.Strings[11])); SendMessage(handle, WM_SETTEXT, 255, Integer(PChar('YC7'))); handle := StrToInt(Trim(Form1.ListBox1.Items.Strings[13])); SendMessage(handle, WM_SETTEXT, 255, Integer(PChar('24X'))); end; end else ShowMessage('抱歉,没有找到!'); end; procedure TForm1.Button2Click(Sender: TObject); var s:string; BHandle:THandle; begin BHandle:=StrToInt(Edit1.Text); S:='你好吗?OK吗?'; SendMessage(BHandle, WM_SETTEXT, 0, LongInt(lpstr(S))); //写入文本字符 end; end.