实现思路分析:
1、找到目标程序的句柄,可以通过窗口的caption属性获取,使用
 FindWindow(nil, 'app caption');
FindWindow(nil, 'app caption');
2、找到你要控制的组件,如Button,使用
 FindWindowEx(ParentHandle, 0, nil, 'btn caption');
FindWindowEx(ParentHandle, 0, nil, 'btn caption');
3、发送Windows消息控制目标程序
 SendMessage( HEdt, BM_CLICK, 0, 0 );
SendMessage( HEdt, BM_CLICK, 0, 0 );
下面是实现该功能的Delphi代码:
 unit Unit1;
unit Unit1;


 Interface usesinterface
Interface usesinterface

 uses
uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls;
  Dialogs, StdCtrls;

 type
type

 TForm1 = Class (class(TForm)
  TForm1 = Class (class(TForm)
 btn1: TButton;
    btn1: TButton;
 mmo1: TMemo;
    mmo1: TMemo;
 edt1: TEdit;
    edt1: TEdit;
 edt2: TEdit;
    edt2: TEdit;
 btn3: TButton;
    btn3: TButton;
 lbl1: TLabel;
    lbl1: TLabel;
 lbl2: TLabel;
    lbl2: TLabel;
 btn4: TButton;
    btn4: TButton;
 procedure btn1Click(Sender: TObject);
    procedure btn1Click(Sender: TObject);
 procedure btn3Click(Sender: TObject);
    procedure btn3Click(Sender: TObject);
 procedure btn4Click(Sender: TObject);
    procedure btn4Click(Sender: TObject);
 private
  private
 { Private declarations }
    { Private declarations }
 public
  public
 { Public declarations }
    { Public declarations }
 end;
  end;

 var
var
 Form1: TForm1;
  Form1: TForm1;

 implementation
implementation

 uses
uses
 ShellAPI;
  ShellAPI;

 {$R *.dfm}
{$R *.dfm}
 var
var
 HApp,
  HApp,
 HEdt : THandle;
  HEdt : THandle;

 procedure TForm1.btn1Click(Sender: TObject);
procedure TForm1.btn1Click(Sender: TObject);
 begin
begin
 HApp := FindWindow(nil, PAnsiChar(edt1.text));
  HApp := FindWindow(nil, PAnsiChar(edt1.text));
 mmo1.Lines.Add(IntToStr(HApp));
  mmo1.Lines.Add(IntToStr(HApp));

 HEdt := FindWindowEx(HApp, 0, nil, PAnsiChar(edt2.text));
  HEdt := FindWindowEx(HApp, 0, nil, PAnsiChar(edt2.text));
 mmo1.Lines.Add(IntToStr(HEdt));
  mmo1.Lines.Add(IntToStr(HEdt));
 SendMessage( HEdt, BM_CLICK, 0, 0 );
  SendMessage( HEdt, BM_CLICK, 0, 0 );
 end;
end;

 procedure TForm1.btn3Click(Sender: TObject);
procedure TForm1.btn3Click(Sender: TObject);
 begin
begin
 ShellExecute(handle, 'open', 'otherapp.exe',nil,nil, SW_SHOWNORMAL{SW_SHOWMAXIMIZED});
  ShellExecute(handle, 'open', 'otherapp.exe',nil,nil, SW_SHOWNORMAL{SW_SHOWMAXIMIZED});
 end;
end;

 procedure TForm1.btn4Click(Sender: TObject);
procedure TForm1.btn4Click(Sender: TObject);
 begin
begin
 SendMessage( HApp, WM_CLOSE, 0, 0 );
  SendMessage( HApp, WM_CLOSE, 0, 0 );
 end;
end;

 end.
end.