试试下面的代码:unit Unit1;interfaceuses Windows, SysUtils, Messages, Classes, Controls, Forms, StdCtrls;type TForm1 = class(TForm) btn1: TButton; procedure btn1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1; I3, I, I7, Ir: Integer;implementation{$R *.dfm}function EnumChildWindowsProc(lHwnd, lParam: Integer): Boolean; stdcall;var Caption: array[0..254] of Char; ClassName: array[0..254] of Char;begin GetWindowText(lHwnd, @Caption, 254); GetClassName(lHwnd, @ClassName, 254); if StrPas(ClassName) = 'Button' then begin if Caption = '3' then I3 := lHwnd; if Caption = '*' then I := lHwnd; if Caption = '7' then I7 := lHwnd; if Caption = '=' then Ir := lHwnd; end; Result := True;end;procedure TForm1.btn1Click(Sender: TObject);var wHandle: HWND; szText: array[0..254] of Char;begin wHandle := GetWindow(Handle, GW_HWNDFIRST); while (wHandle <> 0) do begin if GetWindowText(wHandle, @szText, 255) > 0 then if StrPas(@szText) = '计算器' then // 根据目标窗体的标题查找该窗体句柄 begin EnumChildWindows(wHandle, @EnumChildWindowsProc, 0); // 枚举目标窗体的控件 Break; end; wHandle := GetWindow(wHandle, GW_HWNDNEXT); end; SendMessage(I3, WM_LBUTTONDOWN, 0, 0); SendMessage(I3, WM_LBUTTONUP, 0, 0); SendMessage(I, WM_LBUTTONDOWN, 0, 0); SendMessage(I, WM_LBUTTONUP, 0, 0); SendMessage(I7, WM_LBUTTONDOWN, 0, 0); SendMessage(I7, WM_LBUTTONUP, 0, 0); SendMessage(Ir, WM_LBUTTONDOWN, 0, 0); SendMessage(Ir, WM_LBUTTONUP, 0, 0);end;end.